Skip to content

Commit

Permalink
Fix DotVVM02 warning on overriden ignored property
Browse files Browse the repository at this point in the history
We now ignore override properties if the base has JsonIgnore
or Bind(None) attribute.

Technically, the patch introduces a false negative if the base
is ignored and the derived isn't. However, DotVVM behavior
regarding this is complex (you cannot override JsonIgnore,
only Bind(None)...) and given the rarity of virtual properties,
I don't want to unnecesarily complicate the analyzer.

fix #1784
  • Loading branch information
exyi committed Sep 18, 2024
1 parent 2bbf954 commit 8c43151
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,36 @@ public class DefaultViewModel : DotvvmViewModelBase
await VerifyCS.VerifyAnalyzerAsync(text);
}

[Fact]
public async Task Test_IgnoreNonSerializedMembers_BindDirectionNoneInherited_ViewModel()
{
var text = @"
using DotVVM.Framework.ViewModel;
using Newtonsoft.Json;
using System;
using System.IO;
namespace ConsoleApplication1
{
public class BaseVM : DotvvmViewModelBase
{
[Bind(Direction.None)]
public virtual Stream Property1 { get; }
[JsonIgnore]
public virtual Stream Property2 { get; }
}
public class DefaultViewModel : BaseVM
{
public override Stream Property1 { get; }
public override Stream Property2 { get; }
}
}";

await VerifyCS.VerifyAnalyzerAsync(text, expected: []);
}

[Fact]
public async Task Test_SelfReferencingTypes_GenericArgs_ViewModel()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,11 @@ private static bool IsSerializationOverriden(IPropertySymbol property, Serializa
return false;
}

/// <summary> Returns true if the property has a Bind(Direction.None) or JsonIgnore attribute </summary>
private static bool IsSerializationIgnored(IPropertySymbol property, SerializabilityAnalysisContext context)
{
return IsSerializationIgnoredUsingBindAttribute(property, context) || IsSerializationIgnoredUsingJsonIgnoreAttribute(property, context);
return IsSerializationIgnoredUsingBindAttribute(property, context) || IsSerializationIgnoredUsingJsonIgnoreAttribute(property, context) ||
property.OverriddenProperty is {} overriddenProperty && IsSerializationIgnored(overriddenProperty, context);
}

private static bool IsSerializationIgnoredUsingBindAttribute(ISymbol propertyOrFieldSymbol, SerializabilityAnalysisContext context)
Expand Down

0 comments on commit 8c43151

Please sign in to comment.