diff --git a/src/Analyzers/Analyzers.Tests/Serializability/ViewModelSerializabilityTest.cs b/src/Analyzers/Analyzers.Tests/Serializability/ViewModelSerializabilityTest.cs index 5f1e6a4543..c8aeb43d26 100644 --- a/src/Analyzers/Analyzers.Tests/Serializability/ViewModelSerializabilityTest.cs +++ b/src/Analyzers/Analyzers.Tests/Serializability/ViewModelSerializabilityTest.cs @@ -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() { diff --git a/src/Analyzers/Analyzers/Serializability/ViewModelSerializabilityAnalyzer.cs b/src/Analyzers/Analyzers/Serializability/ViewModelSerializabilityAnalyzer.cs index 95328f6abc..84a55f9d75 100644 --- a/src/Analyzers/Analyzers/Serializability/ViewModelSerializabilityAnalyzer.cs +++ b/src/Analyzers/Analyzers/Serializability/ViewModelSerializabilityAnalyzer.cs @@ -317,9 +317,11 @@ private static bool IsSerializationOverriden(IPropertySymbol property, Serializa return false; } + /// Returns true if the property has a Bind(Direction.None) or JsonIgnore attribute 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)