Skip to content

Commit 14268f3

Browse files
authored
Merge pull request #14792 from tamasvajk/standalone/assembly-attribute
C#: Fix assembly attribute extraction in standalone mode
2 parents 408ba51 + 7a001f4 commit 14268f3

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Populators/TypeContainerVisitor.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ public override void VisitAttributeList(AttributeListSyntax node)
8989
SyntaxKind.ModuleKeyword => Entities.AttributeKind.Module,
9090
_ => throw new InternalError(node, "Unhandled global target")
9191
};
92-
foreach (var attribute in node.Attributes)
92+
var attributes = node.Attributes;
93+
for (var i = 0; i < attributes.Count; i++)
9394
{
95+
var attribute = attributes[i];
9496
if (attributeLookup.Value(attribute) is AttributeData attributeData)
9597
{
9698
var ae = Entities.Attribute.Create(Cx, attributeData, outputAssembly, kind);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| standalone.cs:3:12:3:29 | [assembly: Attribute1(...)] |
2+
| standalone.cs:9:2:9:11 | [Attribute1(...)] |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import csharp
2+
3+
from Attribute a
4+
where a.getType().getName() = "Attribute1Attribute"
5+
select a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: --standalone
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
[assembly: global::Attribute1]
4+
5+
class Attribute1Attribute : Attribute
6+
{
7+
}
8+
9+
[Attribute1]
10+
class A
11+
{
12+
}

0 commit comments

Comments
 (0)