Skip to content

Commit

Permalink
Merge pull request #1858 from riganti/fix-DotVVM02-override
Browse files Browse the repository at this point in the history
Fix DotVVM02 warning on overriden ignored property
  • Loading branch information
exyi authored Oct 10, 2024
2 parents ef57d78 + 8c43151 commit d92e70b
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 d92e70b

Please sign in to comment.