Skip to content

Commit d8a6d10

Browse files
authored
Fix: prevent double implementation of command binder (#420)
* fix the double implementation of command binding * check all interfaces on basetype
1 parent c8dc071 commit d8a6d10

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ public static SyntaxList<MemberDeclarationSyntax> GetProperties(
4747

4848
var nodes = new List<MemberDeclarationSyntax>(properties.Length);
4949

50-
if (!string.IsNullOrWhiteSpace(desiredCommandInterface)
51-
&& !string.IsNullOrWhiteSpace(platformCommandType)
52-
&& namedTypeSymbol.Interfaces.Any(interfaceName => interfaceName.GetFullName().Equals(desiredCommandInterface, StringComparison.Ordinal)))
50+
if (ShouldGenerateCommandBindingProperty(namedTypeSymbol, desiredCommandInterface, platformCommandType))
5351
{
5452
var bindCommandPropertyDeclaration = GetBindCommandPropertyDeclaration(
5553
makeClassesPublic,
@@ -107,6 +105,16 @@ public static SyntaxList<MemberDeclarationSyntax> GetProperties(
107105
return new SyntaxList<MemberDeclarationSyntax>(nodes);
108106
}
109107

108+
private static bool ShouldGenerateCommandBindingProperty(INamedTypeSymbol namedTypeSymbol, string? desiredCommandInterface, string? platformCommandType)
109+
{
110+
return !string.IsNullOrWhiteSpace(desiredCommandInterface)
111+
&& !string.IsNullOrWhiteSpace(platformCommandType)
112+
&& namedTypeSymbol.Interfaces.Any(interfaceName => interfaceName.GetFullName().Equals(desiredCommandInterface, StringComparison.Ordinal))
113+
// we don't want to generate the property if the base class already has it
114+
// this happens if someone incorrectly applies the interface on a subclass as well as the base class
115+
&& (namedTypeSymbol.BaseType == null || namedTypeSymbol.BaseType.AllInterfaces.All(interfaceName => !interfaceName.GetFullName().Equals(desiredCommandInterface, StringComparison.Ordinal)));
116+
}
117+
110118
private static AccessorDeclarationSyntax[] GetAccessorDeclarationSyntaxes()
111119
{
112120
var accessorList = new[]

0 commit comments

Comments
 (0)