Skip to content

Commit 62e7c22

Browse files
committed
C#: Add generic attribute test and expected results.
1 parent 211af19 commit 62e7c22

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
3+
[assembly: MyGenericAttribute<int>()]
4+
[module: MyGeneric2<object, object>()]
5+
6+
public class MyGenericAttribute<T> : Attribute { }
7+
public class MyGeneric2Attribute<T, U> : Attribute { }
8+
9+
public class TestGenericAttribute
10+
{
11+
12+
[MyGenericAttribute<int>()]
13+
public void M1() { }
14+
15+
[MyGeneric<string>()]
16+
public void M2() { }
17+
18+
[MyGeneric2<int, string>()]
19+
public void M3() { }
20+
21+
[return: MyGeneric<object>()]
22+
public int M4() { return 0; }
23+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| GenericAttribute.cs:3:12:3:34 | [assembly: MyGeneric<Int32>(...)] | MyGenericAttribute<Int32> | 1 | (Int32) | GenericAssemblyAttribute |
2+
| GenericAttribute.cs:4:10:4:35 | [module: MyGeneric2<Object,Object>(...)] | MyGeneric2Attribute<Object,Object> | 2 | (Object) | GenericModuleAttribute |
3+
| GenericAttribute.cs:12:6:12:28 | [MyGeneric<Int32>(...)] | MyGenericAttribute<Int32> | 1 | (Int32) | GenericDefaultAttribute |
4+
| GenericAttribute.cs:15:6:15:22 | [MyGeneric<String>(...)] | MyGenericAttribute<String> | 1 | (String) | GenericDefaultAttribute |
5+
| GenericAttribute.cs:18:6:18:28 | [MyGeneric2<Int32,String>(...)] | MyGeneric2Attribute<Int32,String> | 2 | (Int32,String) | GenericDefaultAttribute |
6+
| GenericAttribute.cs:21:14:21:30 | [return: MyGeneric<Object>(...)] | MyGenericAttribute<Object> | 1 | (Object) | GenericReturnAttribute |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import csharp
2+
3+
private string getTypeArguments(GenericAttribute a) {
4+
result = "(" + concat(Type t | t = a.getATypeArgument() | t.getName(), ",") + ")"
5+
}
6+
7+
from GenericAttribute a
8+
where a.getFile().getStem() = "GenericAttribute"
9+
select a, a.getType().getName(), a.getNumberOfTypeArguments(), getTypeArguments(a),
10+
a.getAPrimaryQlClass()

0 commit comments

Comments
 (0)