diff --git a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs index 0db84d2..52edffc 100644 --- a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs +++ b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs @@ -47,9 +47,7 @@ public static SyntaxList GetProperties( var nodes = new List(properties.Length); - if (!string.IsNullOrWhiteSpace(desiredCommandInterface) - && !string.IsNullOrWhiteSpace(platformCommandType) - && namedTypeSymbol.Interfaces.Any(interfaceName => interfaceName.GetFullName().Equals(desiredCommandInterface, StringComparison.Ordinal))) + if (ShouldGenerateCommandBindingProperty(namedTypeSymbol, desiredCommandInterface, platformCommandType)) { var bindCommandPropertyDeclaration = GetBindCommandPropertyDeclaration( makeClassesPublic, @@ -107,6 +105,16 @@ public static SyntaxList GetProperties( return new SyntaxList(nodes); } + private static bool ShouldGenerateCommandBindingProperty(INamedTypeSymbol namedTypeSymbol, string? desiredCommandInterface, string? platformCommandType) + { + return !string.IsNullOrWhiteSpace(desiredCommandInterface) + && !string.IsNullOrWhiteSpace(platformCommandType) + && namedTypeSymbol.Interfaces.Any(interfaceName => interfaceName.GetFullName().Equals(desiredCommandInterface, StringComparison.Ordinal)) + // we don't want to generate the property if the base class already has it + // this happens if someone incorrectly applies the interface on a subclass as well as the base class + && (namedTypeSymbol.BaseType == null || namedTypeSymbol.BaseType.AllInterfaces.All(interfaceName => !interfaceName.GetFullName().Equals(desiredCommandInterface, StringComparison.Ordinal))); + } + private static AccessorDeclarationSyntax[] GetAccessorDeclarationSyntaxes() { var accessorList = new[]