Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DotVVM02 warning on overriden ignored property #1858

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading