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: prevent double implementation of command binder #420

Merged
merged 3 commits into from
Jun 12, 2024
Merged
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 @@ -31,7 +31,7 @@
string? desiredCommandInterface,
bool makeClassesPublic,
bool includeObsoleteItems,
string? platformCommandType)

Check warning on line 34 in src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'platformCommandType' has no matching param tag in the XML comment for 'ControlBindingModelPropertyGenerator.GetProperties(INamedTypeSymbol, string?, bool, bool, string?)' (but other parameters do)

Check warning on line 34 in src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Parameter 'platformCommandType' has no matching param tag in the XML comment for 'ControlBindingModelPropertyGenerator.GetProperties(INamedTypeSymbol, string?, bool, bool, string?)' (but other parameters do)

Check warning on line 34 in src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'platformCommandType' has no matching param tag in the XML comment for 'ControlBindingModelPropertyGenerator.GetProperties(INamedTypeSymbol, string?, bool, bool, string?)' (but other parameters do)
{
if (namedTypeSymbol == null)
{
Expand All @@ -47,9 +47,7 @@

var nodes = new List<MemberDeclarationSyntax>(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,
Expand Down Expand Up @@ -107,6 +105,16 @@
return new SyntaxList<MemberDeclarationSyntax>(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[]
Expand Down
Loading