Skip to content

Commit abc16ab

Browse files
committed
C#: Include AttributeUsages in stub generator
1 parent a5bfeb6 commit abc16ab

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

csharp/extractor/Semmle.Extraction.CSharp.StubGenerator/StubVisitor.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ private void StubTypedConstant(TypedConstant c)
186186
}
187187
break;
188188
case TypedConstantKind.Enum:
189-
stubWriter.Write("throw null");
189+
stubWriter.Write($"({c.Type!.GetQualifiedName()}) ");
190+
stubWriter.Write(c.Value!.ToString());
190191
break;
191192
case TypedConstantKind.Array:
192193
stubWriter.Write("new []{");
@@ -200,7 +201,8 @@ private void StubTypedConstant(TypedConstant c)
200201
}
201202

202203
private static readonly HashSet<string> attributeAllowList = new() {
203-
"System.FlagsAttribute"
204+
"System.FlagsAttribute",
205+
"System.AttributeUsageAttribute"
204206
};
205207

206208
private void StubAttribute(AttributeData a, string prefix)
@@ -219,6 +221,14 @@ private void StubAttribute(AttributeData a, string prefix)
219221
{
220222
stubWriter.Write("(");
221223
WriteCommaSep(a.ConstructorArguments, StubTypedConstant);
224+
if (a.ConstructorArguments.Any() && a.NamedArguments.Any())
225+
stubWriter.Write(",");
226+
WriteCommaSep(a.NamedArguments, arg =>
227+
{
228+
stubWriter.Write(arg.Key);
229+
stubWriter.Write(" = ");
230+
StubTypedConstant(arg.Value);
231+
});
222232
stubWriter.Write(")");
223233
}
224234
stubWriter.WriteLine("]");

0 commit comments

Comments
 (0)