diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/AddMarshalAsToElementFixer.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/AddMarshalAsToElementFixer.cs index dc1037aa5276074c1fb434f26d5985e66508129a..ebb902ff46ff6237293faf23d79eceb8e5add61d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/AddMarshalAsToElementFixer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/AddMarshalAsToElementFixer.cs @@ -1,12 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; -using System.Runtime.InteropServices; -using System.Text; using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs index d476547ba50fc257adc14dd8500b26390a1fd982..de661865516610889d71e2cf1f3616a3d039efc2 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs @@ -46,7 +46,7 @@ public override void Initialize(AnalysisContext context) context.Compilation, targetFramework.TargetFramework, targetFramework.Version, - context.Compilation.SourceModule.GetAttributes().Any(attr => attr.AttributeClass.ToDisplayString() == TypeNames.System_Runtime_CompilerServices_SkipLocalsInitAttribute_Metadata)); + context.Compilation.SourceModule.GetAttributes().Any(attr => attr.AttributeClass.ToDisplayString() == TypeNames.System_Runtime_CompilerServices_SkipLocalsInitAttribute)); context.RegisterSymbolAction(context => { diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs index 250ef2067d9c5184d3bc1b72d2dcdac532657e79..49549260a129be727da6f06f315daf7a6ebfa3d9 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs @@ -104,7 +104,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) private static readonly AttributeSyntax s_comExposedClassAttributeTemplate = Attribute( - GenericName(TypeNames.ComExposedClassAttribute) + GenericName(TypeNames.GlobalAlias + TypeNames.ComExposedClassAttribute) .AddTypeArgumentListArguments( IdentifierName(ClassInfoTypeName))); private static MemberDeclarationSyntax GenerateClassInfoAttributeOnUserType(ContainingSyntaxContext containingSyntaxContext, ContainingSyntax classSyntax) => @@ -124,12 +124,11 @@ private static ClassDeclarationSyntax GenerateClassInfoType(ImmutableArray), sizeof(ComInterfaceEntry) * ); LocalDeclarationStatement( VariableDeclaration( - PointerType( - ParseTypeName(TypeNames.System_Runtime_InteropServices_ComWrappers_ComInterfaceEntry)), + PointerType(TypeSyntaxes.System_Runtime_InteropServices_ComWrappers_ComInterfaceEntry), SingletonSeparatedList( VariableDeclarator(vtablesLocal) .WithInitializer(EqualsValueClause( CastExpression( - PointerType( - ParseTypeName(TypeNames.System_Runtime_InteropServices_ComWrappers_ComInterfaceEntry)), + PointerType(TypeSyntaxes.System_Runtime_InteropServices_ComWrappers_ComInterfaceEntry), InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - ParseTypeName(TypeNames.System_Runtime_CompilerServices_RuntimeHelpers), + TypeSyntaxes.System_Runtime_CompilerServices_RuntimeHelpers, IdentifierName("AllocateTypeAssociatedMemory"))) .AddArgumentListArguments( Argument(TypeOfExpression(IdentifierName(ClassInfoTypeName))), Argument( BinaryExpression( SyntaxKind.MultiplyExpression, - SizeOfExpression(ParseTypeName(TypeNames.System_Runtime_InteropServices_ComWrappers_ComInterfaceEntry)), + SizeOfExpression(TypeSyntaxes.System_Runtime_InteropServices_ComWrappers_ComInterfaceEntry), LiteralExpression( SyntaxKind.NumericLiteralExpression, Literal(implementedInterfaces.Length))))))))))), // IIUnknownDerivedDetails details; LocalDeclarationStatement( VariableDeclaration( - ParseTypeName(TypeNames.IIUnknownDerivedDetails), + TypeSyntaxes.IIUnknownDerivedDetails, SingletonSeparatedList( VariableDeclarator(detailsTempLocal)))) }; @@ -180,7 +177,7 @@ private static ClassDeclarationSyntax GenerateClassInfoType(ImmutableArray { - context.AddSource(data.TypeName.Replace("global::", ""), data.Source); + context.AddSource(data.TypeName.Replace(TypeNames.GlobalAlias, ""), data.Source); }); } private static readonly AttributeSyntax s_iUnknownDerivedAttributeTemplate = Attribute( - GenericName(TypeNames.IUnknownDerivedAttribute) + GenericName(TypeNames.GlobalAlias + TypeNames.IUnknownDerivedAttribute) .AddTypeArgumentListArguments( IdentifierName("InterfaceInformation"), IdentifierName("InterfaceImplementation"))); @@ -452,7 +452,7 @@ private static InterfaceDeclarationSyntax GenerateImplementationInterface(ComInt .Select(ctx => ctx.Stub.Node) .Concat(shadowImplementations) .Concat(inheritedStubs))) - .AddAttributeLists(AttributeList(SingletonSeparatedList(Attribute(ParseName(TypeNames.System_Runtime_InteropServices_DynamicInterfaceCastableImplementationAttribute))))); + .AddAttributeLists(AttributeList(SingletonSeparatedList(Attribute(NameSyntaxes.System_Runtime_InteropServices_DynamicInterfaceCastableImplementationAttribute)))); } private static InterfaceDeclarationSyntax GenerateImplementationVTableMethods(ComInterfaceAndMethodsContext comInterfaceAndMethods, CancellationToken _) @@ -496,7 +496,7 @@ private static InterfaceDeclarationSyntax GenerateImplementationVTable(ComInterf CastExpression(VoidStarStarSyntax, InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - ParseTypeName(TypeNames.System_Runtime_CompilerServices_RuntimeHelpers), + TypeSyntaxes.System_Runtime_CompilerServices_RuntimeHelpers, IdentifierName("AllocateTypeAssociatedMemory"))) .AddArgumentListArguments( Argument(TypeOfExpression(interfaceType.Syntax)), @@ -525,7 +525,7 @@ private static InterfaceDeclarationSyntax GenerateImplementationVTable(ComInterf ExpressionStatement( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - ParseTypeName(TypeNames.System_Runtime_InteropServices_ComWrappers), + TypeSyntaxes.System_Runtime_InteropServices_ComWrappers, IdentifierName("GetIUnknownImpl"))) .AddArgumentListArguments( Argument(IdentifierName("v0")) @@ -586,7 +586,7 @@ private static InterfaceDeclarationSyntax GenerateImplementationVTable(ComInterf InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseTypeName(TypeNames.System_Runtime_InteropServices_NativeMemory), + TypeSyntaxes.System_Runtime_InteropServices_NativeMemory, IdentifierName("Copy"))) .WithArgumentList( ArgumentList( @@ -601,7 +601,7 @@ private static InterfaceDeclarationSyntax GenerateImplementationVTable(ComInterf SyntaxKind.SimpleMemberAccessExpression, MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseTypeName(TypeNames.StrategyBasedComWrappers), + TypeSyntaxes.StrategyBasedComWrappers, IdentifierName("DefaultIUnknownInterfaceDetailsStrategy")), IdentifierName("GetIUnknownDerivedDetails"))) .WithArgumentList( @@ -643,14 +643,14 @@ private static InterfaceDeclarationSyntax GenerateImplementationVTable(ComInterf private static readonly ClassDeclarationSyntax InterfaceInformationTypeTemplate = ClassDeclaration("InterfaceInformation") .AddModifiers(Token(SyntaxKind.FileKeyword), Token(SyntaxKind.UnsafeKeyword)) - .AddBaseListTypes(SimpleBaseType(ParseTypeName(TypeNames.IIUnknownInterfaceType))); + .AddBaseListTypes(SimpleBaseType(TypeSyntaxes.IIUnknownInterfaceType)); private static ClassDeclarationSyntax GenerateInterfaceInformation(ComInterfaceInfo context, CancellationToken _) { ClassDeclarationSyntax interfaceInformationType = InterfaceInformationTypeTemplate .AddMembers( // public static System.Guid Iid { get; } = new(); - PropertyDeclaration(ParseTypeName(TypeNames.System_Guid), "Iid") + PropertyDeclaration(TypeSyntaxes.System_Guid, "Iid") .AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)) .AddAccessorListAccessors( AccessorDeclaration(SyntaxKind.GetAccessorDeclaration).WithSemicolonToken(Token(SyntaxKind.SemicolonToken))) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs index 30c0e66f3cf3dd336350a1926b6b308d5bfe7285..0aed46284aa53ef170f8c452f9e5e17e16ba3ebb 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs @@ -123,7 +123,7 @@ private static bool IsInPartialContext(INamedTypeSymbol symbol, InterfaceDeclara stringMarshallingDiagnostic = DiagnosticInfo.Create( GeneratorDiagnostics.StringMarshallingCustomTypeNotAccessibleByGeneratedCode, syntax.Identifier.GetLocation(), - attrInfo.StringMarshallingCustomType.FullTypeName.Replace("global::", ""), + attrInfo.StringMarshallingCustomType.FullTypeName.Replace(TypeNames.GlobalAlias, ""), details); return false; } diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComMethodContext.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComMethodContext.cs index 72dcb670f5b9fe8c1c07d25b6aacae11793f748b..e81e2ce06895de203e75e2b8757805ecb58dfea7 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComMethodContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComMethodContext.cs @@ -114,7 +114,7 @@ private MethodDeclarationSyntax CreateUnreachableExceptionStub() .WithExpressionBody(ArrowExpressionClause( ThrowExpression( ObjectCreationExpression( - ParseTypeName(TypeNames.UnreachableException)) + TypeSyntaxes.UnreachableException) .WithArgumentList(ArgumentList())))); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ManagedToNativeVTableMethodGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ManagedToNativeVTableMethodGenerator.cs index dd18f01bb7c88b3f0b98c95be2a4882736273de3..4207abc73af3e4df5bcf9137aade3612ece57af4 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ManagedToNativeVTableMethodGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ManagedToNativeVTableMethodGenerator.cs @@ -115,7 +115,7 @@ public BlockSyntax GenerateStubBody(int index, ImmutableArray new PointerTypeInfo( - $"{TypeNames.System_Runtime_InteropServices_ComWrappers_ComInterfaceDispatch}*", + $"{TypeNames.GlobalAlias + TypeNames.System_Runtime_InteropServices_ComWrappers_ComInterfaceDispatch}*", $"{TypeNames.System_Runtime_InteropServices_ComWrappers_ComInterfaceDispatch}*", IsFunctionPointer: false); public IEnumerable Generate(TypePositionInfo info, StubCodeContext context) @@ -47,7 +47,7 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont IdentifierName(managed), InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_ComWrappers_ComInterfaceDispatch), + TypeSyntaxes.System_Runtime_InteropServices_ComWrappers_ComInterfaceDispatch, GenericName( Identifier("GetInstance"), TypeArgumentList(SingletonSeparatedList(info.ManagedType.Syntax)))), diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ManagedHResultExceptionMarshallerFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ManagedHResultExceptionMarshallerFactory.cs index 63017cf51265a4d2a1dd38d394280616ec0aab29..ad96c9b6b3bc87cde3093951ea1ad40546c2b1de 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ManagedHResultExceptionMarshallerFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ManagedHResultExceptionMarshallerFactory.cs @@ -62,7 +62,7 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont yield return ExpressionStatement( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_Marshal), + TypeSyntaxes.System_Runtime_InteropServices_Marshal, IdentifierName("ThrowExceptionForHR")), ArgumentList( SingletonSeparatedList(Argument(IdentifierName(managedIdentifier)))))); diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ObjectUnwrapperMarshallerFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ObjectUnwrapperMarshallerFactory.cs index c04a3a7ccfbb10c71d0e6792d63f24235595b905..1ed3dd0d49ec5c1fcc59cb45c4786934d6644190 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ObjectUnwrapperMarshallerFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ObjectUnwrapperMarshallerFactory.cs @@ -47,7 +47,7 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseTypeName(TypeNames.UnmanagedObjectUnwrapper), + TypeSyntaxes.UnmanagedObjectUnwrapper, GenericName(Identifier("GetObjectForUnmanagedWrapper")) .WithTypeArgumentList( TypeArgumentList( diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs index fe931a812bf341940eb7a9ad3ca62aa9c17b3c96..647312729b28dc0695ebc3e26b961c2fbb691ef3 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs @@ -85,7 +85,7 @@ internal static class VirtualMethodPointerStubGenerator (ParameterListSyntax unmanagedParameterList, TypeSyntax returnType, _) = stubGenerator.GenerateAbiMethodSignatureData(); AttributeSyntax unmanagedCallersOnlyAttribute = Attribute( - ParseName(TypeNames.UnmanagedCallersOnlyAttribute)); + NameSyntaxes.UnmanagedCallersOnlyAttribute); if (methodStub.CallingConvention.Array.Length != 0) { @@ -94,7 +94,7 @@ internal static class VirtualMethodPointerStubGenerator ImplicitArrayCreationExpression( InitializerExpression(SyntaxKind.CollectionInitializerExpression, SeparatedList( - methodStub.CallingConvention.Array.Select(callConv => TypeOfExpression(ParseName($"System.Runtime.CompilerServices.CallConv{callConv.Name.ValueText}"))))))) + methodStub.CallingConvention.Array.Select(callConv => TypeOfExpression(TypeSyntaxes.CallConv(callConv.Name.ValueText))))))) .WithNameEquals(NameEquals(IdentifierName("CallConvs")))); } @@ -132,7 +132,7 @@ private static ImmutableArray AddImplicitElementInfos(Incremen { elements.Add( new TypePositionInfo( - new ReferenceTypeInfo($"global::{TypeNames.System_Exception}", TypeNames.System_Exception), + new ReferenceTypeInfo(TypeNames.GlobalAlias + TypeNames.System_Exception, TypeNames.System_Exception), methodStub.ExceptionMarshallingInfo) { InstanceIdentifier = "__exception", diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs index e5faa6fbadd6f2983d0ccd0ea1fd1bc913d117ec..f826cd130a7d2b7f67e815047c4340cc955b4cef 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs @@ -413,9 +413,6 @@ private static MarshallingInfo CreateExceptionMarshallingInfo(AttributeData virt // Verify there is an [UnmanagedObjectUnwrapperAttribute] if (!method.ContainingType.GetAttributes().Any(att => att.AttributeClass.IsOfType(TypeNames.UnmanagedObjectUnwrapperAttribute))) - //!method.ContainingType.GetAttributes().Any(att => - //att.AttributeClass.MetadataName == TypeNames.UnmanagedObjectUnwrapperAttribute.Substring(TypeNames.UnmanagedObjectUnwrapperAttribute.LastIndexOf('.') + 1) - //&& att.AttributeClass.OriginalDefinition.ToDisplayString().Substring(0, att.AttributeClass.OriginalDefinition.ToDisplayString().LastIndexOf(att.AttributeClass.ToDisplayString())) == TypeNames.UnmanagedObjectUnwrapperAttribute.Substring(0, TypeNames.UnmanagedObjectUnwrapperAttribute.LastIndexOf('.')))) { return Diagnostic.Create(GeneratorDiagnostics.InvalidAttributedMethodContainingTypeMissingUnmanagedObjectUnwrapperAttribute, methodSyntax.Identifier.GetLocation(), method.Name); } @@ -429,7 +426,7 @@ private static MemberDeclarationSyntax GenerateNativeInterfaceMetadata(Containin InterfaceDeclaration("Native") .WithModifiers(TokenList(Token(SyntaxKind.InternalKeyword), Token(SyntaxKind.PartialKeyword))) .WithBaseList(BaseList(SingletonSeparatedList((BaseTypeSyntax)SimpleBaseType(IdentifierName(context.ContainingSyntax[0].Identifier))))) - .AddAttributeLists(AttributeList(SingletonSeparatedList(Attribute(ParseName(TypeNames.System_Runtime_InteropServices_DynamicInterfaceCastableImplementationAttribute)))))); + .AddAttributeLists(AttributeList(SingletonSeparatedList(Attribute(NameSyntaxes.System_Runtime_InteropServices_DynamicInterfaceCastableImplementationAttribute))))); } private static MemberDeclarationSyntax GeneratePopulateVTableMethod(IGrouping vtableMethods) diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/AddDisableRuntimeMarshallingAttributeFixer.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/AddDisableRuntimeMarshallingAttributeFixer.cs index c7ede679e5983148d53cb414f10f00ec2ea0968b..d08e76d952cf9b5fc5c9beec3be35731fca4e653 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/AddDisableRuntimeMarshallingAttributeFixer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/AddDisableRuntimeMarshallingAttributeFixer.cs @@ -1,12 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis; diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs index 558a4fb161437e237f465314c41ebfc7b5de6116..ee34a5931abf327725ff37cf4170746dba9e0377 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs @@ -62,7 +62,7 @@ public override void Initialize(AnalysisContext context) context.Compilation, targetFramework.TargetFramework, targetFramework.Version, - context.Compilation.SourceModule.GetAttributes().Any(attr => attr.AttributeClass.ToDisplayString() == TypeNames.System_Runtime_CompilerServices_SkipLocalsInitAttribute_Metadata)); + context.Compilation.SourceModule.GetAttributes().Any(attr => attr.AttributeClass.ToDisplayString() == TypeNames.System_Runtime_CompilerServices_SkipLocalsInitAttribute)); context.RegisterSymbolAction(symbolContext => AnalyzeSymbol(symbolContext, libraryImportAttrType, env), SymbolKind.Method); }); diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportFixer.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportFixer.cs index 60d6796869d3389848aea7250f7335dd4cd3edae..8fd974ba2f90c083621bcc6e3c06a75445da1252 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportFixer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportFixer.cs @@ -196,7 +196,7 @@ private static string AppendSuffix(string entryPoint, char? entryPointSuffix) char? entryPointSuffix, CancellationToken cancellationToken) { - INamedTypeSymbol? dllImportAttrType = editor.SemanticModel.Compilation.GetBestTypeByMetadataName(typeof(DllImportAttribute).FullName); + INamedTypeSymbol? dllImportAttrType = editor.SemanticModel.Compilation.GetBestTypeByMetadataName(TypeNames.DllImportAttribute); if (dllImportAttrType == null) return methodSyntax; diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs index fcd915ea25f606ad6f1b613ea82e4a58fd953b11..6b3bd184664973dd0b55965688f0f830da59b4e0 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs @@ -113,11 +113,11 @@ private static List GenerateSyntaxForForwardedAttributes(Attrib if (suppressGCTransitionAttribute is not null) { - attributes.Add(Attribute(ParseName(TypeNames.SuppressGCTransitionAttribute))); + attributes.Add(Attribute(NameSyntaxes.SuppressGCTransitionAttribute)); } if (unmanagedCallConvAttribute is not null) { - AttributeSyntax unmanagedCallConvSyntax = Attribute(ParseName(TypeNames.UnmanagedCallConvAttribute)); + AttributeSyntax unmanagedCallConvSyntax = Attribute(NameSyntaxes.UnmanagedCallConvAttribute); foreach (KeyValuePair arg in unmanagedCallConvAttribute.NamedArguments) { if (arg.Key == CallConvsField) @@ -129,7 +129,7 @@ private static List GenerateSyntaxForForwardedAttributes(Attrib TypeOfExpression(((ITypeSymbol)callConv.Value!).AsTypeSyntax())); } - ArrayTypeSyntax arrayOfSystemType = ArrayType(ParseTypeName(TypeNames.System_Type), SingletonList(ArrayRankSpecifier())); + ArrayTypeSyntax arrayOfSystemType = ArrayType(TypeSyntaxes.System_Type, SingletonList(ArrayRankSpecifier())); unmanagedCallConvSyntax = unmanagedCallConvSyntax.AddArgumentListArguments( AttributeArgument( @@ -143,9 +143,9 @@ private static List GenerateSyntaxForForwardedAttributes(Attrib if (defaultDllImportSearchPathsAttribute is not null) { attributes.Add( - Attribute(ParseName(TypeNames.DefaultDllImportSearchPathsAttribute)).AddArgumentListArguments( + Attribute(NameSyntaxes.DefaultDllImportSearchPathsAttribute).AddArgumentListArguments( AttributeArgument( - CastExpression(ParseTypeName(TypeNames.DllImportSearchPath), + CastExpression(TypeSyntaxes.DllImportSearchPath, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)defaultDllImportSearchPathsAttribute.ConstructorArguments[0].Value!)))))); } @@ -424,26 +424,26 @@ private static MemberDeclarationSyntax PrintForwarderStub(ContainingSyntax userD SingletonList(AttributeList( SingletonSeparatedList( Attribute( - ParseName(typeof(DllImportAttribute).FullName), - AttributeArgumentList( - SeparatedList( - new[] - { - AttributeArgument(LiteralExpression( - SyntaxKind.StringLiteralExpression, - Literal(libraryImportData.ModuleName))), - AttributeArgument( - NameEquals(nameof(DllImportAttribute.EntryPoint)), - null, - LiteralExpression( - SyntaxKind.StringLiteralExpression, - Literal(libraryImportData.EntryPoint ?? stubMethodName))), - AttributeArgument( - NameEquals(nameof(DllImportAttribute.ExactSpelling)), - null, - LiteralExpression(SyntaxKind.TrueLiteralExpression)) - } - ))))))) + NameSyntaxes.DllImportAttribute, + AttributeArgumentList( + SeparatedList( + new[] + { + AttributeArgument(LiteralExpression( + SyntaxKind.StringLiteralExpression, + Literal(libraryImportData.ModuleName))), + AttributeArgument( + NameEquals(nameof(DllImportAttribute.EntryPoint)), + null, + LiteralExpression( + SyntaxKind.StringLiteralExpression, + Literal(libraryImportData.EntryPoint ?? stubMethodName))), + AttributeArgument( + NameEquals(nameof(DllImportAttribute.ExactSpelling)), + null, + LiteralExpression(SyntaxKind.TrueLiteralExpression)) + } + ))))))) .WithParameterList(parameterList); if (returnTypeAttributes is not null) { @@ -486,7 +486,7 @@ private static AttributeSyntax CreateForwarderDllImport(LibraryImportData target // Create new attribute return Attribute( - ParseName(typeof(DllImportAttribute).FullName), + NameSyntaxes.DllImportAttribute, AttributeArgumentList(SeparatedList(newAttributeArgs))); static ExpressionSyntax CreateBoolExpressionSyntax(bool trueOrFalse) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/GeneratedStatements.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/GeneratedStatements.cs index d611eb59cd3b40dbc7c5fd73aeb3c095a132c3b3..896487328de530222f44e3104f71044e3abaf8fa 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/GeneratedStatements.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/GeneratedStatements.cs @@ -168,7 +168,7 @@ private static ImmutableArray GenerateCatchClauseForManagedEx managedExceptionMarshaller.TypeInfo, context with { CurrentStage = StubCodeContext.Stage.PinnedMarshal })); return ImmutableArray.Create( CatchClause( - CatchDeclaration(ParseTypeName(TypeNames.System_Exception), Identifier(managed)), + CatchDeclaration(TypeSyntaxes.System_Exception, Identifier(managed)), filter: null, Block(List(catchClauseBuilder)))); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalGeneratorInitializationContextExtensions.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalGeneratorInitializationContextExtensions.cs index 7a30a442e1085e43f78f807f074fc2d250eb2588..18ae8e90d58cd2adeeec663691cc8ab7804448cf 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalGeneratorInitializationContextExtensions.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalGeneratorInitializationContextExtensions.cs @@ -21,7 +21,7 @@ public static IncrementalValueProvider CreateStubEnvironmentPro var isModuleSkipLocalsInit = context.SyntaxProvider .ForAttributeWithMetadataName( - TypeNames.System_Runtime_CompilerServices_SkipLocalsInitAttribute_Metadata, + TypeNames.System_Runtime_CompilerServices_SkipLocalsInitAttribute, (node, ct) => node is ICompilationUnitSyntax, // If SkipLocalsInit is applied at the top level, it is either applied to the module // or is invalid syntax. As a result, we just need to know if there's any top-level diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DelegateMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DelegateMarshaller.cs index 3f8631a3d4ab2a6f9a0d28f93756a19f5fe49b9f..b4b4c01c5b3d4e40bf71f8fb516f96cf287e9036 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DelegateMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DelegateMarshaller.cs @@ -53,7 +53,7 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_Marshal), + TypeSyntaxes.System_Runtime_InteropServices_Marshal, IdentifierName("GetFunctionPointerForDelegate")), ArgumentList(SingletonSeparatedList(Argument(IdentifierName(managedIdentifier))))), LiteralExpression(SyntaxKind.DefaultLiteralExpression)))); @@ -75,7 +75,7 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_Marshal), + TypeSyntaxes.System_Runtime_InteropServices_Marshal, GenericName(Identifier("GetDelegateForFunctionPointer")) .WithTypeArgumentList( TypeArgumentList( diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ElementsMarshalling.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ElementsMarshalling.cs index 136de0e4cca534a949dc18e95c470b0bca4a31bd..10c7d7a8c34fd8d69f68423d9df66371ed79f26e 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ElementsMarshalling.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ElementsMarshalling.cs @@ -113,7 +113,7 @@ public override StatementSyntax GenerateUnmanagedToManagedByValueOutMarshalState InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_MemoryMarshal), + TypeSyntaxes.System_Runtime_InteropServices_MemoryMarshal, IdentifierName("CreateSpan")), ArgumentList( SeparatedList(new[] @@ -121,7 +121,7 @@ public override StatementSyntax GenerateUnmanagedToManagedByValueOutMarshalState Argument( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_MemoryMarshal), + TypeSyntaxes.System_Runtime_InteropServices_MemoryMarshal, IdentifierName("GetReference")), ArgumentList(SingletonSeparatedList( Argument(CollectionSource.GetUnmanagedValuesSource(info, context)))))) @@ -167,7 +167,7 @@ public override StatementSyntax GenerateManagedToUnmanagedByValueOutUnmarshalSta ExpressionSyntax destination = InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_MemoryMarshal), + TypeSyntaxes.System_Runtime_InteropServices_MemoryMarshal, IdentifierName("CreateSpan")), ArgumentList( SeparatedList(new[] @@ -175,7 +175,7 @@ public override StatementSyntax GenerateManagedToUnmanagedByValueOutUnmarshalSta Argument( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_MemoryMarshal), + TypeSyntaxes.System_Runtime_InteropServices_MemoryMarshal, IdentifierName("GetReference")), ArgumentList(SingletonSeparatedList( Argument(CollectionSource.GetManagedValuesSource(info, context)))))) @@ -223,7 +223,7 @@ private ExpressionSyntax CastToManagedIfNecessary(ExpressionSyntax expression) return InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseTypeName(TypeNames.System_Runtime_InteropServices_MemoryMarshal), + TypeSyntaxes.System_Runtime_InteropServices_MemoryMarshal, GenericName( Identifier("Cast"), TypeArgumentList(SeparatedList( @@ -369,7 +369,7 @@ public override StatementSyntax GenerateManagedToUnmanagedByValueOutUnmarshalSta InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_MemoryMarshal), + TypeSyntaxes.System_Runtime_InteropServices_MemoryMarshal, IdentifierName("CreateSpan"))) .WithArgumentList( ArgumentList( @@ -379,7 +379,7 @@ public override StatementSyntax GenerateManagedToUnmanagedByValueOutUnmarshalSta Argument( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_CompilerServices_Unsafe), + TypeSyntaxes.System_Runtime_CompilerServices_Unsafe, IdentifierName("AsRef")), ArgumentList(SingletonSeparatedList( Argument( @@ -493,7 +493,7 @@ public override StatementSyntax GenerateUnmanagedToManagedByValueOutMarshalState InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_MemoryMarshal), + TypeSyntaxes.System_Runtime_InteropServices_MemoryMarshal, IdentifierName("CreateSpan"))) .WithArgumentList( ArgumentList( @@ -503,7 +503,7 @@ public override StatementSyntax GenerateUnmanagedToManagedByValueOutMarshalState Argument( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_CompilerServices_Unsafe), + TypeSyntaxes.System_Runtime_CompilerServices_Unsafe, IdentifierName("AsRef")), ArgumentList(SingletonSeparatedList( Argument( diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallerHelpers.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallerHelpers.cs index 325f4741600ac4f5b972220391d9df5545b25fe6..38200e9f694b56564fdf4a129fca5696c4b6c6ce 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallerHelpers.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallerHelpers.cs @@ -12,7 +12,7 @@ namespace Microsoft.Interop { public static class MarshallerHelpers { - public static readonly TypeSyntax SystemIntPtrType = ParseTypeName(TypeNames.System_IntPtr); + public static readonly TypeSyntax SystemIntPtrType = TypeSyntaxes.System_IntPtr; public static ForStatementSyntax GetForLoop(ExpressionSyntax lengthExpression, string indexerIdentifier) { @@ -96,7 +96,7 @@ public static TypeSyntax GetCompatibleGenericTypeParameterSyntax(this TypeSyntax if (spanElementTypeSyntax is PointerTypeSyntax) { // Pointers cannot be passed to generics, so use IntPtr for this case. - spanElementTypeSyntax = SystemIntPtrType; + spanElementTypeSyntax = TypeSyntaxes.System_IntPtr; } return spanElementTypeSyntax; } @@ -108,7 +108,7 @@ public static TypeSyntax GetCompatibleGenericTypeParameterSyntax(this TypeSyntax InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_Marshal), + TypeSyntaxes.System_Runtime_InteropServices_Marshal, IdentifierName("SetLastSystemError")), ArgumentList(SingletonSeparatedList( Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(errorCode))))))); @@ -122,7 +122,7 @@ public static TypeSyntax GetCompatibleGenericTypeParameterSyntax(this TypeSyntax InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_Marshal), + TypeSyntaxes.System_Runtime_InteropServices_Marshal, IdentifierName("GetLastSystemError"))))); // Marshal.SetLastPInvokeError(); @@ -131,7 +131,7 @@ public static TypeSyntax GetCompatibleGenericTypeParameterSyntax(this TypeSyntax InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_InteropServices_Marshal), + TypeSyntaxes.System_Runtime_InteropServices_Marshal, IdentifierName("SetLastPInvokeError")), ArgumentList(SingletonSeparatedList( Argument(IdentifierName(lastErrorIdentifier)))))); @@ -327,7 +327,7 @@ public static StatementSyntax SkipInitOrDefaultInit(TypePositionInfo info, StubC return ExpressionStatement( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - ParseName(TypeNames.System_Runtime_CompilerServices_Unsafe), + TypeSyntaxes.System_Runtime_CompilerServices_Unsafe, IdentifierName("SkipInit"))) .WithArgumentList( ArgumentList(SingletonSeparatedList( diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorExtensions.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorExtensions.cs index 2c11351959b038ae19cc8549d10da1f8ace7d5b3..7773df2475d2cbc07ab8994612edcaee71e18875 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorExtensions.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorExtensions.cs @@ -137,9 +137,9 @@ private static bool TryRehydrateMarshalAsAttribute(TypePositionInfo info, out At // so explicitly do not resurface a [MarshalAs(UnmanagdType.CustomMarshaler)] attribute. if (info.MarshallingAttributeInfo is MarshalAsInfo { UnmanagedType: not UnmanagedType.CustomMarshaler } marshalAs) { - marshalAsAttribute = Attribute(ParseName(TypeNames.System_Runtime_InteropServices_MarshalAsAttribute)) + marshalAsAttribute = Attribute(NameSyntaxes.System_Runtime_InteropServices_MarshalAsAttribute) .WithArgumentList(AttributeArgumentList(SingletonSeparatedList(AttributeArgument( - CastExpression(ParseTypeName(TypeNames.System_Runtime_InteropServices_UnmanagedType), + CastExpression(TypeSyntaxes.System_Runtime_InteropServices_UnmanagedType, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)marshalAs.UnmanagedType))))))); return true; @@ -184,7 +184,7 @@ private static bool TryRehydrateMarshalAsAttribute(TypePositionInfo info, out At List marshalAsArguments = new List { AttributeArgument( - CastExpression(ParseTypeName(TypeNames.System_Runtime_InteropServices_UnmanagedType), + CastExpression(TypeSyntaxes.System_Runtime_InteropServices_UnmanagedType, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)UnmanagedType.LPArray)))) }; @@ -213,12 +213,12 @@ private static bool TryRehydrateMarshalAsAttribute(TypePositionInfo info, out At { marshalAsArguments.Add( AttributeArgument(NameEquals("ArraySubType"), null, - CastExpression(ParseTypeName(TypeNames.System_Runtime_InteropServices_UnmanagedType), + CastExpression(TypeSyntaxes.System_Runtime_InteropServices_UnmanagedType, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)elementMarshalAs.UnmanagedType)))) ); } - marshalAsAttribute = Attribute(ParseName(TypeNames.System_Runtime_InteropServices_MarshalAsAttribute)) + marshalAsAttribute = Attribute(NameSyntaxes.System_Runtime_InteropServices_MarshalAsAttribute) .WithArgumentList(AttributeArgumentList(SeparatedList(marshalAsArguments))); return true; } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/PointerNativeTypeAssignmentRewriter.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/PointerNativeTypeAssignmentRewriter.cs index 6ce89e8377f4b4b8c781aff40cde91093d373aa9..5f4f5d43a4a3df925865c3e68b8330eed0976f42 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/PointerNativeTypeAssignmentRewriter.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/PointerNativeTypeAssignmentRewriter.cs @@ -35,7 +35,7 @@ public PointerNativeTypeAssignmentRewriter(string nativeIdentifier, PointerTypeS { return node.WithInitializer( EqualsValueClause( - CastExpression(MarshallerHelpers.SystemIntPtrType, node.Initializer.Value))); + CastExpression(TypeSyntaxes.System_IntPtr, node.Initializer.Value))); } if (node.Initializer.Value.ToString() == _nativeIdentifier) { @@ -52,7 +52,7 @@ public override SyntaxNode VisitAssignmentExpression(AssignmentExpressionSyntax if (node.Left.ToString() == _nativeIdentifier) { return node.WithRight( - CastExpression(MarshallerHelpers.SystemIntPtrType, node.Right)); + CastExpression(TypeSyntaxes.System_IntPtr, node.Right)); } if (node.Right.ToString() == _nativeIdentifier) { diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/SafeHandleMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/SafeHandleMarshaller.cs index 9f4700ec00f9361909c43ca17cfc1192d4c8e31a..c45b94483bd4457efbca332057849aca58ccc7df 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/SafeHandleMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/SafeHandleMarshaller.cs @@ -77,7 +77,7 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - ParseTypeName(TypeNames.System_Activator), + TypeSyntaxes.System_Activator, IdentifierName("CreateInstance"))) .WithArgumentList( ArgumentList( @@ -168,7 +168,7 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont StatementSyntax unmarshalStatement = ExpressionStatement( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - ParseTypeName(TypeNames.System_Runtime_InteropServices_Marshal), + TypeSyntaxes.System_Runtime_InteropServices_Marshal, IdentifierName("InitHandle")), ArgumentList(SeparatedList( new[] diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs index 89c85ee235a34e2b3416c473f6a829bc5ddf39eb..c382262bd47b4a8f5e923737268ae31aea2eef88 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs @@ -1,14 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Diagnostics; -using System.Linq; -using System.Runtime.InteropServices; namespace Microsoft.Interop { @@ -155,7 +150,7 @@ internal static MarshallingInfo CreateSpecificMarshallingInfo(ManagedTypeInfo un { return unmanagedReturnType switch { - SpecialTypeInfo(_, _, SpecialType.System_Void) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionAsVoidMarshaller}", unmanagedReturnType), + SpecialTypeInfo(_, _, SpecialType.System_Void) => CreateWellKnownComExceptionMarshallingData(TypeNames.ExceptionAsVoidMarshaller, unmanagedReturnType), SpecialTypeInfo(_, _, SpecialType.System_Int32) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionAsHResultMarshaller}", unmanagedReturnType), SpecialTypeInfo(_, _, SpecialType.System_UInt32) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionAsHResultMarshaller}", unmanagedReturnType), SpecialTypeInfo(_, _, SpecialType.System_Single) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionAsNaNMarshaller}", unmanagedReturnType), @@ -165,7 +160,7 @@ internal static MarshallingInfo CreateSpecificMarshallingInfo(ManagedTypeInfo un static NativeMarshallingAttributeInfo CreateWellKnownComExceptionMarshallingData(string marshallerName, ManagedTypeInfo unmanagedType) { - ManagedTypeInfo marshallerTypeInfo = new ReferenceTypeInfo(marshallerName, marshallerName); + ManagedTypeInfo marshallerTypeInfo = new ReferenceTypeInfo(TypeNames.GlobalAlias + marshallerName, marshallerName); return new NativeMarshallingAttributeInfo(marshallerTypeInfo, new CustomTypeMarshallers(ImmutableDictionary.Empty.Add( MarshalMode.UnmanagedToManagedOut, diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SignatureContext.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SignatureContext.cs index 6c1365f9265f1f2ef028dab5c00c4ad5ee84233c..5a93922a5bb1386474d163d702e4c1b7c8a02683 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SignatureContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SignatureContext.cs @@ -86,7 +86,7 @@ public IEnumerable StubParameters AttributeList( SingletonSeparatedList( Attribute( - ParseName(TypeNames.System_CodeDom_Compiler_GeneratedCodeAttribute_WithGlobal), + NameSyntaxes.System_CodeDom_Compiler_GeneratedCodeAttribute, AttributeArgumentList( SeparatedList( new[] @@ -104,7 +104,7 @@ public IEnumerable StubParameters // Adding the skip locals init indiscriminately since the source generator is // targeted at non-blittable method signatures which typically will contain locals // in the generated code. - Attribute(ParseName(TypeNames.System_Runtime_CompilerServices_SkipLocalsInitAttribute_WithGlobal))))); + Attribute(NameSyntaxes.System_Runtime_CompilerServices_SkipLocalsInitAttribute)))); } return new SignatureContext() @@ -187,7 +187,7 @@ private static bool MethodIsSkipLocalsInit(StubEnvironment env, IMethodSymbol me return false; static bool IsSkipLocalsInitAttribute(AttributeData a) - => a.AttributeClass?.ToDisplayString() == TypeNames.System_Runtime_CompilerServices_SkipLocalsInitAttribute_Metadata; + => a.AttributeClass?.ToDisplayString() == TypeNames.System_Runtime_CompilerServices_SkipLocalsInitAttribute; } } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StringMarshallingInfoProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StringMarshallingInfoProvider.cs index 05a060019ab3f5f203d4985a5cfa31c294deaf9c..12f69adfef136b48f4feb6606d38fd89854d725a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StringMarshallingInfoProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StringMarshallingInfoProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Collections.Generic; -using System.Text; using Microsoft.CodeAnalysis; namespace Microsoft.Interop diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs index dac6c2658ccd5b84fdf151874e4c6bf04b24fd30..ff75472d71feece3a1e889e8daaec04bd9f7d4f0 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs @@ -1,10 +1,143 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; + namespace Microsoft.Interop { + public static class NameSyntaxes + { + private static NameSyntax? _DllImportAttribute; + public static NameSyntax DllImportAttribute => _DllImportAttribute ??= ParseName(TypeNames.GlobalAlias + TypeNames.DllImportAttribute); + + private static NameSyntax? _LibraryImportAttribute; + public static NameSyntax LibraryImportAttribute => _LibraryImportAttribute ??= ParseName(TypeNames.GlobalAlias + TypeNames.LibraryImportAttribute); + + private static NameSyntax? _System_Runtime_InteropServices_DynamicInterfaceCastableImplementationAttribute; + public static NameSyntax System_Runtime_InteropServices_DynamicInterfaceCastableImplementationAttribute => _System_Runtime_InteropServices_DynamicInterfaceCastableImplementationAttribute ??= ParseName(TypeNames.GlobalAlias + TypeNames.System_Runtime_InteropServices_DynamicInterfaceCastableImplementationAttribute); + + private static NameSyntax? _System_Runtime_InteropServices_MarshalAsAttribute; + public static NameSyntax System_Runtime_InteropServices_MarshalAsAttribute => _System_Runtime_InteropServices_MarshalAsAttribute ??= ParseName(TypeNames.GlobalAlias + TypeNames.System_Runtime_InteropServices_MarshalAsAttribute); + + private static NameSyntax? _DefaultDllImportSearchPathsAttribute; + public static NameSyntax DefaultDllImportSearchPathsAttribute => _DefaultDllImportSearchPathsAttribute ??= ParseName(TypeNames.GlobalAlias + TypeNames.DefaultDllImportSearchPathsAttribute); + + private static NameSyntax? _SuppressGCTransitionAttribute; + public static NameSyntax SuppressGCTransitionAttribute => _SuppressGCTransitionAttribute ??= ParseName(TypeNames.GlobalAlias + TypeNames.SuppressGCTransitionAttribute); + + private static NameSyntax? _UnmanagedCallConvAttribute; + public static NameSyntax UnmanagedCallConvAttribute => _UnmanagedCallConvAttribute ??= ParseName(TypeNames.GlobalAlias + TypeNames.UnmanagedCallConvAttribute); + + private static NameSyntax? _System_Runtime_CompilerServices_SkipLocalsInitAttribute; + public static NameSyntax System_Runtime_CompilerServices_SkipLocalsInitAttribute => _System_Runtime_CompilerServices_SkipLocalsInitAttribute ??= ParseName(TypeNames.GlobalAlias + TypeNames.System_Runtime_CompilerServices_SkipLocalsInitAttribute); + + private static NameSyntax? _System_CodeDom_Compiler_GeneratedCodeAttribute; + public static NameSyntax System_CodeDom_Compiler_GeneratedCodeAttribute => _System_CodeDom_Compiler_GeneratedCodeAttribute ??= ParseName(TypeNames.GlobalAlias + TypeNames.System_CodeDom_Compiler_GeneratedCodeAttribute); + + private static NameSyntax? _UnmanagedCallersOnlyAttribute; + public static NameSyntax UnmanagedCallersOnlyAttribute => _UnmanagedCallersOnlyAttribute ??= ParseName(TypeNames.GlobalAlias + TypeNames.UnmanagedCallersOnlyAttribute); + } + + public static class TypeSyntaxes + { + private static TypeSyntax? _StringMarshalling; + public static TypeSyntax StringMarshalling => _StringMarshalling ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.StringMarshalling); + + private static TypeSyntax? _System_Runtime_InteropServices_ComWrappers_ComInterfaceEntry; + public static TypeSyntax System_Runtime_InteropServices_ComWrappers_ComInterfaceEntry => _System_Runtime_InteropServices_ComWrappers_ComInterfaceEntry ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Runtime_InteropServices_ComWrappers_ComInterfaceEntry); + + private static TypeSyntax? _System_Runtime_InteropServices_NativeMemory; + public static TypeSyntax System_Runtime_InteropServices_NativeMemory => _System_Runtime_InteropServices_NativeMemory ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Runtime_InteropServices_NativeMemory); + + private static TypeSyntax? _StrategyBasedComWrappers; + public static TypeSyntax StrategyBasedComWrappers => _StrategyBasedComWrappers ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.StrategyBasedComWrappers); + + private static TypeSyntax? _IUnmanagedVirtualMethodTableProvider; + public static TypeSyntax IUnmanagedVirtualMethodTableProvider => _IUnmanagedVirtualMethodTableProvider ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.IUnmanagedVirtualMethodTableProvider); + + private static TypeSyntax? _IIUnknownInterfaceType; + public static TypeSyntax IIUnknownInterfaceType => _IIUnknownInterfaceType ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.IIUnknownInterfaceType); + + private static TypeSyntax? _IIUnknownDerivedDetails; + public static TypeSyntax IIUnknownDerivedDetails => _IIUnknownDerivedDetails ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.IIUnknownDerivedDetails); + + private static TypeSyntax? _UnmanagedObjectUnwrapper; + public static TypeSyntax UnmanagedObjectUnwrapper => _UnmanagedObjectUnwrapper ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.UnmanagedObjectUnwrapper); + + private static TypeSyntax? _IComExposedClass; + public static TypeSyntax IComExposedClass => _IComExposedClass ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.IComExposedClass); + + private static TypeSyntax? _UnreachableException; + public static TypeSyntax UnreachableException => _UnreachableException ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.UnreachableException); + + private static TypeSyntax? _System_Runtime_CompilerServices_RuntimeHelpers; + public static TypeSyntax System_Runtime_CompilerServices_RuntimeHelpers => _System_Runtime_CompilerServices_RuntimeHelpers ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Runtime_CompilerServices_RuntimeHelpers); + + private static TypeSyntax? _System_Runtime_InteropServices_ComWrappers; + public static TypeSyntax System_Runtime_InteropServices_ComWrappers => _System_Runtime_InteropServices_ComWrappers ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Runtime_InteropServices_ComWrappers); + + private static TypeSyntax? _System_IntPtr; + public static TypeSyntax System_IntPtr => _System_IntPtr ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_IntPtr); + + private static TypeSyntax? _System_Guid; + public static TypeSyntax System_Guid => _System_Guid ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Guid); + + private static TypeSyntax? _DllImportSearchPath; + public static TypeSyntax DllImportSearchPath => _DllImportSearchPath ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.DllImportSearchPath); + + private static TypeSyntax? _System_Type; + public static TypeSyntax System_Type => _System_Type ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Type); + + private static TypeSyntax? _System_Activator; + public static TypeSyntax System_Activator => _System_Activator ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Activator); + + private static TypeSyntax? _System_Runtime_InteropServices_Marshal; + public static TypeSyntax System_Runtime_InteropServices_Marshal => _System_Runtime_InteropServices_Marshal ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Runtime_InteropServices_Marshal); + + private static TypeSyntax? _System_Runtime_InteropServices_UnmanagedType; + public static TypeSyntax System_Runtime_InteropServices_UnmanagedType => _System_Runtime_InteropServices_UnmanagedType ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Runtime_InteropServices_UnmanagedType); + + private static TypeSyntax? _System_Runtime_InteropServices_MemoryMarshal; + public static TypeSyntax System_Runtime_InteropServices_MemoryMarshal => _System_Runtime_InteropServices_MemoryMarshal ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Runtime_InteropServices_MemoryMarshal); + + private static TypeSyntax? _System_Exception; + public static TypeSyntax System_Exception => _System_Exception ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Exception); + + private static TypeSyntax? _System_GC; + public static TypeSyntax System_GC => _System_GC ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_GC); + + private static TypeSyntax? _System_Runtime_InteropServices_ComWrappers_ComInterfaceDispatch; + public static TypeSyntax System_Runtime_InteropServices_ComWrappers_ComInterfaceDispatch => _System_Runtime_InteropServices_ComWrappers_ComInterfaceDispatch ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Runtime_InteropServices_ComWrappers_ComInterfaceDispatch); + + private static TypeSyntax? _System_Runtime_CompilerServices_Unsafe; + public static TypeSyntax System_Runtime_CompilerServices_Unsafe => _System_Runtime_CompilerServices_Unsafe ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.System_Runtime_CompilerServices_Unsafe); + + private static TypeSyntax? _CallConvCdecl; + private static TypeSyntax? _CallConvFastcall; + private static TypeSyntax? _CallConvMemberFunction; + private static TypeSyntax? _CallConvStdcall; + private static TypeSyntax? _CallConvSuppressGCTransition; + private static TypeSyntax? _CallConvThiscall; + public static TypeSyntax CallConv(string callConv) + { + return callConv switch + { + "Cdecl" => _CallConvCdecl ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.CallConvCdeclName), + "Fastcall" => _CallConvFastcall ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.CallConvFastcallName), + "MemberFunction" => _CallConvMemberFunction ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.CallConvMemberFunctionName), + "Stdcall" => _CallConvStdcall ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.CallConvStdcallName), + "SuppressGCTransition" => _CallConvSuppressGCTransition ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.CallConvSuppressGCTransitionName), + "Thiscall" => _CallConvThiscall ??= ParseTypeName(TypeNames.GlobalAlias + TypeNames.CallConvThiscallName), + _ => throw new ArgumentException($"Unexpected CallConv: {callConv}") + }; + } + } public static class TypeNames { + public const string GlobalAlias = "global::"; + public const string DllImportAttribute = "System.Runtime.InteropServices.DllImportAttribute"; public const string LibraryImportAttribute = "System.Runtime.InteropServices.LibraryImportAttribute"; public const string LibraryImportAttribute_ShortName = "LibraryImportAttribute"; @@ -46,9 +179,9 @@ public static class TypeNames public const string IUnmanagedInterfaceType_Metadata = "System.Runtime.InteropServices.Marshalling.IUnmanagedInterfaceType"; public const string System_Span_Metadata = "System.Span`1"; - public const string System_Span = "System.Span"; + public const string System_Span = GlobalAlias + "System.Span"; public const string System_ReadOnlySpan_Metadata = "System.ReadOnlySpan`1"; - public const string System_ReadOnlySpan = "System.ReadOnlySpan"; + public const string System_ReadOnlySpan = GlobalAlias + "System.ReadOnlySpan"; public const string System_IntPtr = "System.IntPtr"; @@ -94,9 +227,7 @@ public static string MarshalEx(InteropGenerationOptions options) public const string System_Runtime_InteropServices_InAttribute = "System.Runtime.InteropServices.InAttribute"; - public const string System_Runtime_CompilerServices_SkipLocalsInitAttribute_WithGlobal = "global::System.Runtime.CompilerServices.SkipLocalsInitAttribute"; - - public const string System_Runtime_CompilerServices_SkipLocalsInitAttribute_Metadata = "System.Runtime.CompilerServices.SkipLocalsInitAttribute"; + public const string System_Runtime_CompilerServices_SkipLocalsInitAttribute = "System.Runtime.CompilerServices.SkipLocalsInitAttribute"; public const string System_Runtime_CompilerServices_Unsafe = "System.Runtime.CompilerServices.Unsafe"; @@ -106,7 +237,7 @@ public static string MarshalEx(InteropGenerationOptions options) public const string DllImportSearchPath = "System.Runtime.InteropServices.DllImportSearchPath"; - public const string System_CodeDom_Compiler_GeneratedCodeAttribute_WithGlobal = "global::System.CodeDom.Compiler.GeneratedCodeAttribute"; + public const string System_CodeDom_Compiler_GeneratedCodeAttribute = "System.CodeDom.Compiler.GeneratedCodeAttribute"; public const string System_Runtime_InteropServices_DynamicInterfaceCastableImplementationAttribute = "System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute"; @@ -162,5 +293,12 @@ public static string MarshalEx(InteropGenerationOptions options) public const string System_Runtime_InteropServices_CULong = "System.Runtime.InteropServices.CULong"; public const string System_Runtime_InteropServices_NFloat = "System.Runtime.InteropServices.NFloat"; + + public const string CallConvCdeclName = "System.Runtime.CompilerServices.CallConvCdecl"; + public const string CallConvFastcallName = "System.Runtime.CompilerServices.CallConvFastcall"; + public const string CallConvStdcallName = "System.Runtime.CompilerServices.CallConvStdcall"; + public const string CallConvThiscallName = "System.Runtime.CompilerServices.CallConvThiscall"; + public const string CallConvSuppressGCTransitionName = "System.Runtime.CompilerServices.CallConvSuppressGCTransition"; + public const string CallConvMemberFunctionName = "System.Runtime.CompilerServices.CallConvMemberFunction"; } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ComInterfaceGenerator.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ComInterfaceGenerator.Tests.csproj index 7385b403905e02fb64f4d338b8b813af561645f5..4c953e51ddb7a8d1fd2fdb0a9d226f36032f82a9 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ComInterfaceGenerator.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ComInterfaceGenerator.Tests.csproj @@ -13,6 +13,7 @@ + diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/CustomMarshallingTests.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/CustomMarshallingTests.cs index 4608a11b6a2d304bc8d55cc740f72f4cdf7d7270..9262e5a36d5151d73a4237540ace9300932ab85e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/CustomMarshallingTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/CustomMarshallingTests.cs @@ -16,6 +16,8 @@ partial class NativeExportsNE { internal partial class Stateless { + public static string System = "Make sure generated code prefixes type references with global::"; + [LibraryImport(NativeExportsNE_Binary, EntryPoint = "stringcontainer_deepduplicate")] public static partial void DeepDuplicateStrings(StringContainer strings, out StringContainer pStringsOut); diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/AddDisableRuntimeMarshallingAttributeFixerTests.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/AddDisableRuntimeMarshallingAttributeFixerTests.cs index 92a6aab6b177b03fde53c892e73a565970eb87a2..e54b6b77a1a1fcbf9500499b286fd81d9e81df23 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/AddDisableRuntimeMarshallingAttributeFixerTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/AddDisableRuntimeMarshallingAttributeFixerTests.cs @@ -4,12 +4,11 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.IO; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Testing; using Microsoft.Interop; using Xunit; -using System.IO; - using VerifyCS = Microsoft.Interop.UnitTests.Verifiers.CSharpCodeFixVerifier< Microsoft.CodeAnalysis.Testing.EmptyDiagnosticAnalyzer, Microsoft.Interop.Analyzers.AddDisableRuntimeMarshallingAttributeFixer>; diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/AdditionalAttributesOnStub.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/AdditionalAttributesOnStub.cs index 72e9a8bb87c0b394c470c58494e1040261097bc7..cf85b92c678c9535d123306b77c5b4f482715f0e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/AdditionalAttributesOnStub.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/AdditionalAttributesOnStub.cs @@ -4,6 +4,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Testing; +using Microsoft.Interop; using Microsoft.Interop.UnitTests; using System.Collections.Generic; using System.Linq; @@ -286,7 +287,7 @@ bool ValidateAttribute(AttributeData attr) } AttributeSyntax syntax = (AttributeSyntax)attr.ApplicationSyntaxReference!.GetSyntax(); - return syntax.Name.ToString().StartsWith("global::"); + return syntax.Name.ToString().StartsWith(TypeNames.GlobalAlias); } } else diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/ISystem.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/ISystem.cs new file mode 100644 index 0000000000000000000000000000000000000000..0e4584c098258732663f29661e6e974a6aebacf6 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/ISystem.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.Marshalling; + +namespace SharedTypes.ComInterfaces +{ + [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf8)] + [Guid(IID)] + internal partial interface ISystem + { + // Make sure method names System and Microsoft don't interfere with framework type / method references + void Microsoft(int p); + void System(int p); + public const string IID = "3BFFE3FD-D11E-4195-8250-0C73321977A0"; + } +}