C#: Add testcase for CIL generic attribute extraction.

This commit is contained in:
Michael Nebel
2023-01-17 15:58:36 +01:00
parent 821d294be8
commit 3846349ba0
6 changed files with 35 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
using System;
namespace Assembly
{
public class MyAssemblyGeneric1Attribute<T> : Attribute { }
public class MyAssemblyGeneric2Attribute<T, U> : Attribute { }
public class TestAssemblyGenericAttribute
{
[MyAssemblyGeneric1Attribute<object>()]
public void M1() { }
[MyAssemblyGeneric2<int, string>()]
public void M2() { }
}
}

Binary file not shown.

View File

@@ -0,0 +1,7 @@
using System;
using Assembly;
public class Class1
{
public static void Main(string[] args) { }
}

View File

@@ -0,0 +1,2 @@
| assembly.dll:0:0:0:0 | [MyAssemblyGeneric1Attribute<Object>(...)] | MyAssemblyGeneric1Attribute<Object> | 1 | (Object) |
| assembly.dll:0:0:0:0 | [MyAssemblyGeneric2Attribute<Int32,String>(...)] | MyAssemblyGeneric2Attribute<Int32,String> | 2 | (Int32,String) |

View File

@@ -0,0 +1,9 @@
import semmle.code.cil.CIL
private string getTypeArguments(GenericAttribute a) {
result = "(" + concat(Type t | t = a.getATypeArgument() | t.getName(), ",") + ")"
}
from GenericAttribute a
where a.getFile().getStem() = "assembly"
select a, a.getType().getName(), a.getNumberOfTypeArguments(), getTypeArguments(a)

View File

@@ -0,0 +1 @@
semmle-extractor-options: --cil