@@ -65,8 +65,6 @@ public sealed partial class PInvokeGenerator : IDisposable
65
65
private readonly HashSet < string > _usedRemappings ;
66
66
private readonly string _placeholderMacroType ;
67
67
68
- private bool _hasAnnotateAttr ;
69
-
70
68
private string _filePath ;
71
69
private string [ ] _clangCommandLineArgs ;
72
70
private CXTranslationUnit_Flags _translationFlags ;
@@ -800,16 +798,18 @@ static void GenerateNativeTypeNameAttribute(PInvokeGenerator generator, Stream?
800
798
801
799
static void GenerateNativeAnnotationAttribute ( PInvokeGenerator generator , Stream ? stream , bool leaveStreamOpen )
802
800
{
801
+ const string AttributeName = "NativeAnnotationAttribute" ;
803
802
var config = generator . Config ;
804
803
805
- if ( ! generator . _hasAnnotateAttr )
804
+ var ns = generator . GetNamespace ( AttributeName ) ;
805
+ if ( config . ExcludedNames . Contains ( AttributeName ) || config . ExcludedNames . Contains ( $ "{ ns } .{ AttributeName } ") )
806
806
{
807
807
return ;
808
808
}
809
809
810
810
if ( stream is null )
811
811
{
812
- var outputPath = Path . Combine ( config . OutputLocation , "NativeAnnotationAttribute .cs") ;
812
+ var outputPath = Path . Combine ( config . OutputLocation , $ " { AttributeName } .cs") ;
813
813
stream = generator . _outputStreamFactory ( outputPath ) ;
814
814
}
815
815
@@ -828,7 +828,7 @@ static void GenerateNativeAnnotationAttribute(PInvokeGenerator generator, Stream
828
828
sw . WriteLine ( ) ;
829
829
830
830
sw . Write ( "namespace " ) ;
831
- sw . Write ( generator . GetNamespace ( "NativeAnnotationAttribute" ) ) ;
831
+ sw . Write ( ns ) ;
832
832
833
833
if ( generator . Config . GenerateFileScopedNamespaces )
834
834
{
@@ -849,18 +849,18 @@ static void GenerateNativeAnnotationAttribute(PInvokeGenerator generator, Stream
849
849
sw . Write ( indentString ) ;
850
850
sw . WriteLine ( "[Conditional(\" DEBUG\" )]" ) ;
851
851
sw . Write ( indentString ) ;
852
- sw . WriteLine ( "internal sealed partial class NativeAnnotationAttribute : Attribute" ) ;
852
+ sw . WriteLine ( $ "internal sealed partial class { AttributeName } : Attribute") ;
853
853
sw . Write ( indentString ) ;
854
854
sw . WriteLine ( '{' ) ;
855
855
sw . Write ( indentString ) ;
856
856
sw . WriteLine ( " private readonly string _annotation;" ) ;
857
857
sw . WriteLine ( ) ;
858
858
sw . Write ( indentString ) ;
859
- sw . WriteLine ( " /// <summary>Initializes a new instance of the <see cref=\" NativeAnnotationAttribute \" /> class.</summary>" ) ;
859
+ sw . WriteLine ( $ " /// <summary>Initializes a new instance of the <see cref=\" { AttributeName } \" /> class.</summary>") ;
860
860
sw . Write ( indentString ) ;
861
861
sw . WriteLine ( " /// <param name=\" annotation\" >The annotation that was used in the native declaration.</param>" ) ;
862
862
sw . Write ( indentString ) ;
863
- sw . WriteLine ( " public NativeAnnotationAttribute (string annotation)" ) ;
863
+ sw . WriteLine ( $ " public { AttributeName } (string annotation)") ;
864
864
sw . Write ( indentString ) ;
865
865
sw . WriteLine ( " {" ) ;
866
866
sw . Write ( indentString ) ;
@@ -6817,7 +6817,6 @@ private void WithAttributes(NamedDecl namedDecl, bool onlySupportedOSPlatform =
6817
6817
6818
6818
case CX_AttrKind_Annotate :
6819
6819
{
6820
- _hasAnnotateAttr = true ;
6821
6820
var annotationText = attr . Spelling ;
6822
6821
outputBuilder . WriteCustomAttribute ( $ """ NativeAnnotation("{ annotationText } ")""" ) ;
6823
6822
break ;
0 commit comments