From 7e2b9b4f0ee4283bc2d67cfa1edf6a6403bf9a4d Mon Sep 17 00:00:00 2001 From: David Vreony Date: Fri, 14 Jun 2024 23:59:15 +0100 Subject: [PATCH] fix: overriden properties (#423) * add avalonia generation * Update ReactiveUI.Avalonia.ViewToViewModelBindings.csproj * add base dll * fix "new" properties * add avalonia int test * fix override detection not working --- .../ControlBindingModelPropertyGenerator.cs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs index 3346dda..823a50c 100644 --- a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs +++ b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs @@ -77,7 +77,7 @@ public static SyntaxList GetProperties( continue; } - var treatAsNewImplementation = ReplacesBaseProperty(propertySymbol); + var treatAsNewImplementation = ReplacesBaseProperty(propertySymbol, namedTypeSymbol); var accessorList = GetAccessorDeclarationSyntaxes(); @@ -139,11 +139,31 @@ private static MemberDeclarationSyntax GetBindCommandPropertyDeclaration( platformCommandType); } - private static bool ReplacesBaseProperty(IPropertySymbol propertySymbol) + private static bool ReplacesBaseProperty( + IPropertySymbol propertySymbol, + INamedTypeSymbol namedTypeSymbol) { - var accessor = propertySymbol.GetMethod ?? propertySymbol.SetMethod; + var wantedName = propertySymbol.Name; + var baseType = namedTypeSymbol.BaseType; + while (baseType != null) + { + var nameMatches = baseType.GetMembers() + .Where(x => x.Kind == SymbolKind.Property && x.Name.Equals(wantedName, StringComparison.Ordinal)) + .Cast() + .ToImmutableArray(); + + foreach (var nameMatch in nameMatches) + { + if (SymbolEqualityComparer.Default.Equals(nameMatch.Type, propertySymbol.Type)) + { + return !propertySymbol.IsOverride; + } + } + + baseType = baseType.BaseType; + } - return accessor is { HidesBaseMethodsByName: true }; + return false; } private static PropertyDeclarationSyntax GetBindCommandPropertyDeclaration(