Skip to content

Commit

Permalink
fix: overriden properties (#423)
Browse files Browse the repository at this point in the history
* add avalonia generation

* Update ReactiveUI.Avalonia.ViewToViewModelBindings.csproj

* add base dll

* fix "new" properties

* add avalonia int test

* fix override detection not working
  • Loading branch information
dpvreony authored Jun 14, 2024
1 parent 163301b commit 7e2b9b4
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static SyntaxList<MemberDeclarationSyntax> GetProperties(
continue;
}

var treatAsNewImplementation = ReplacesBaseProperty(propertySymbol);
var treatAsNewImplementation = ReplacesBaseProperty(propertySymbol, namedTypeSymbol);

var accessorList = GetAccessorDeclarationSyntaxes();

Expand Down Expand Up @@ -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<IPropertySymbol>()
.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(
Expand Down

0 comments on commit 7e2b9b4

Please sign in to comment.