diff --git a/eng/Versions.props b/eng/Versions.props index c4960e1d3fd1bd..1178bbad1afe6a 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -36,16 +36,16 @@ This version is a moving target until we ship. It should never go ahead of the Roslyn version included in the SDK version in dotnet/arcade's global.json to avoid causing breaks in product construction. --> - 4.2.0-2.final + 4.3.0-2.final 3.3.3 - 4.3.0-1.22206.2 - 4.3.0-1.22206.2 - 4.3.0-1.22206.2 + 4.3.0-2.final + 4.3.0-2.final + 4.3.0-2.final 7.0.0-preview1.22362.3 - 4.3.0-1.22206.2 + 4.3.0-2.final diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs index e32ccc145f6594..eba67b0b5c63e7 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs @@ -12,6 +12,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.DotnetRuntime.Extensions; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; [assembly: System.Resources.NeutralResourcesLanguage("en-US")] @@ -61,19 +62,13 @@ public static class StepNames public void Initialize(IncrementalGeneratorInitializationContext context) { var attributedMethods = context.SyntaxProvider - .CreateSyntaxProvider( - static (node, ct) => ShouldVisitNode(node), - static (context, ct) => - { - MethodDeclarationSyntax syntax = (MethodDeclarationSyntax)context.Node; - if (context.SemanticModel.GetDeclaredSymbol(syntax, ct) is IMethodSymbol methodSymbol - && methodSymbol.GetAttributes().Any(static attribute => attribute.AttributeClass?.ToDisplayString() == TypeNames.LibraryImportAttribute)) - { - return new { Syntax = syntax, Symbol = methodSymbol }; - } - - return null; - }) + .ForAttributeWithMetadataName( + context, + TypeNames.LibraryImportAttribute, + static (node, ct) => node is MethodDeclarationSyntax, + static (context, ct) => context.TargetSymbol is IMethodSymbol methodSymbol + ? new { Syntax = (MethodDeclarationSyntax)context.TargetNode, Symbol = methodSymbol } + : null) .Where( static modelData => modelData is not null); @@ -584,19 +579,6 @@ static ExpressionSyntax CreateEnumExpressionSyntax(T value) where T : Enum } } - private static bool ShouldVisitNode(SyntaxNode syntaxNode) - { - // We only support C# method declarations. - if (syntaxNode.Language != LanguageNames.CSharp - || !syntaxNode.IsKind(SyntaxKind.MethodDeclaration)) - { - return false; - } - - // Filter out methods with no attributes early. - return ((MethodDeclarationSyntax)syntaxNode).AttributeLists.Count > 0; - } - private static Diagnostic? GetDiagnosticIfInvalidMethodForGeneration(MethodDeclarationSyntax methodSyntax, IMethodSymbol method) { // Verify the method has no generic types or defined implementation diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj index 5806bf43f581ca..ab8172b6979078 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj @@ -35,4 +35,19 @@ + + + + + + + + + + + + + + +