From 1fbbdfc8e4e90c0266e17a63b60d3cb44d889104 Mon Sep 17 00:00:00 2001 From: Frederik91 <11948105+Frederik91@users.noreply.github.com> Date: Fri, 6 Jun 2025 08:35:04 +0200 Subject: [PATCH 1/2] Fix async method detection for fully-qualified Task return types --- MakeInterface.Generator/InterfaceGenerator.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/MakeInterface.Generator/InterfaceGenerator.cs b/MakeInterface.Generator/InterfaceGenerator.cs index 28dc4ae..8481e50 100644 --- a/MakeInterface.Generator/InterfaceGenerator.cs +++ b/MakeInterface.Generator/InterfaceGenerator.cs @@ -382,7 +382,19 @@ private bool MethodIsAsync(MethodDeclarationSyntax methodSyntax) if (methodSyntax.Modifiers.Any(x => x.IsKind(SyntaxKind.AsyncKeyword))) return true; - return methodSyntax.ReturnType is GenericNameSyntax genericName && genericName.Identifier.Text == "Task" || methodSyntax.ReturnType.ToString() == "Task"; + return IsTaskReturnType(methodSyntax.ReturnType); + } + + private static bool IsTaskReturnType(TypeSyntax typeSyntax) + { + return typeSyntax switch + { + IdentifierNameSyntax name => name.Identifier.Text == "Task", + GenericNameSyntax generic => generic.Identifier.Text == "Task", + QualifiedNameSyntax qualified => IsTaskReturnType(qualified.Right), + AliasQualifiedNameSyntax alias => IsTaskReturnType(alias.Name), + _ => false, + }; } private static bool IsNotValidInterfaceNamber(ISymbol member) From c4e147a1db1659f9c0fa7a2494860d5afc0b7d53 Mon Sep 17 00:00:00 2001 From: Frederik91 <11948105+Frederik91@users.noreply.github.com> Date: Fri, 6 Jun 2025 09:57:40 +0200 Subject: [PATCH 2/2] Add fully qualified Task handling and update package version --- MakeInterface.Generator/MakeInterface.Generator.csproj | 2 +- MakeInterface.Tests/InterfaceGeneratorTests.cs | 8 +++++++- ...terfaceGeneratorTests.RelayCommand#ITest.g.verified.cs | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/MakeInterface.Generator/MakeInterface.Generator.csproj b/MakeInterface.Generator/MakeInterface.Generator.csproj index 650d887..3272971 100644 --- a/MakeInterface.Generator/MakeInterface.Generator.csproj +++ b/MakeInterface.Generator/MakeInterface.Generator.csproj @@ -12,7 +12,7 @@ library netstandard2.0 MakeInterface.Generator - 0.4.1 + 0.4.1-preview1 Frederik Tegnander COWI Interfaces;SourceGenerator;MakeInterface diff --git a/MakeInterface.Tests/InterfaceGeneratorTests.cs b/MakeInterface.Tests/InterfaceGeneratorTests.cs index 96517c6..ef74d1a 100644 --- a/MakeInterface.Tests/InterfaceGeneratorTests.cs +++ b/MakeInterface.Tests/InterfaceGeneratorTests.cs @@ -187,7 +187,13 @@ private void Test2() { } [RelayCommand] private void Test7(string _) { } - } + + [RelayCommand] + private System.Threading.Tasks.Task Test8() { return System.Threading.Tasks.Task.CompletedTask; } + + [RelayCommand] + private global::System.Threading.Tasks.Task Test9() { return global::System.Threading.Tasks.Task.CompletedTask; } + } } """; diff --git a/MakeInterface.Tests/Snapshots/InterfaceGeneratorTests.RelayCommand#ITest.g.verified.cs b/MakeInterface.Tests/Snapshots/InterfaceGeneratorTests.RelayCommand#ITest.g.verified.cs index 6c3bdbd..f79ea5b 100644 --- a/MakeInterface.Tests/Snapshots/InterfaceGeneratorTests.RelayCommand#ITest.g.verified.cs +++ b/MakeInterface.Tests/Snapshots/InterfaceGeneratorTests.RelayCommand#ITest.g.verified.cs @@ -29,5 +29,11 @@ public partial interface IClass1 // This property was generated because of the RelayCommand attribute applied to the 'Test7' method. See https://aka.ms/CommunityToolkit.MVVM global::CommunityToolkit.Mvvm.Input.IRelayCommand Test7Command { get; } + + // This property was generated because of the RelayCommand attribute applied to the 'Test8' method. See https://aka.ms/CommunityToolkit.MVVM + global::CommunityToolkit.Mvvm.Input.IAsyncRelayCommand Test8Command { get; } + + // This property was generated because of the RelayCommand attribute applied to the 'Test9' method. See https://aka.ms/CommunityToolkit.MVVM + global::CommunityToolkit.Mvvm.Input.IAsyncRelayCommand Test9Command { get; } } } \ No newline at end of file