diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index e973324a..e2c2966b 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -6765,7 +6765,7 @@ private void WithAttributes(NamedDecl namedDecl, bool onlySupportedOSPlatform = var outputBuilder = isTestOutput ? _testOutputBuilder : _outputBuilder; Debug.Assert(outputBuilder is not null); - if (TryGetRemappedValue(namedDecl, _config.WithAttributes, out var attributes)) + if (TryGetRemappedValue(namedDecl, _config.WithAttributes, out var attributes, matchStar: true)) { foreach (var attribute in attributes.Where((a) => !onlySupportedOSPlatform || a.StartsWith("SupportedOSPlatform(", StringComparison.Ordinal))) { diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/OptionsTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/OptionsTest.cs index 5ceeceaf..f2c8bbaf 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/OptionsTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/OptionsTest.cs @@ -54,4 +54,41 @@ public partial struct StructD return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withUsings: withUsings); } + + [Test] + public Task WithAttributes() + { + var inputContents = @"struct StructA {}; struct StructB {}; struct StructC {}; struct StructD {};"; + var expectedOutputContents = +@"namespace ClangSharp.Test +{ + [A] + public partial struct StructA + { + } + + [B] + public partial struct StructB + { + } + + [Star] + public partial struct StructC + { + } + + [Star] + public partial struct StructD + { + } +} +"; + var withAttributes = new Dictionary> { + ["StructA"] = [@"A"], + ["StructB"] = [@"B"], + ["*"] = [@"Star"], + }; + + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withAttributes: withAttributes); + } }