2
2
using System . Collections ;
3
3
using System . Collections . Generic ;
4
4
using System . Collections . ObjectModel ;
5
+ using System . Diagnostics . CodeAnalysis ;
5
6
using System . Runtime . CompilerServices ;
6
7
using System . Text . RegularExpressions ;
7
8
@@ -14,15 +15,15 @@ public partial class ReflectionExtensionsTest
14
15
{
15
16
private static object [ ] _source =
16
17
{
17
- new object [ ] { typeof ( List < int > ) , "System.Collections.Generic.List`1[System.Int32], mscorlib" } ,
18
- new object [ ] { typeof ( List < > ) , "System.Collections.Generic.List`1[T] , mscorlib" } ,
19
- new object [ ] { typeof ( IList < int > ) , "System.Collections.Generic.IList`1[System.Int32], mscorlib" } ,
20
- new object [ ] { typeof ( Dictionary < , > ) , "System.Collections.Generic.Dictionary`2[TKey,TValue] , mscorlib" } ,
21
- new object [ ] { typeof ( Dictionary < int , string > ) , "System.Collections.Generic.Dictionary`2[System.Int32,System.String], mscorlib" } ,
22
- new object [ ] { typeof ( Dictionary < int , List < int > > ) , "System.Collections.Generic.Dictionary`2[System.Int32,System.Collections.Generic.List`1[System.Int32]], mscorlib" } ,
18
+ new object [ ] { typeof ( List < int > ) , "System.Collections.Generic.List`1[[ System.Int32, mscorlib] ], mscorlib" } ,
19
+ new object [ ] { typeof ( List < > ) , "System.Collections.Generic.List`1, mscorlib" } ,
20
+ new object [ ] { typeof ( IList < int > ) , "System.Collections.Generic.IList`1[[ System.Int32, mscorlib] ], mscorlib" } ,
21
+ new object [ ] { typeof ( Dictionary < , > ) , "System.Collections.Generic.Dictionary`2, mscorlib" } ,
22
+ new object [ ] { typeof ( Dictionary < int , string > ) , "System.Collections.Generic.Dictionary`2[[ System.Int32, mscorlib],[ System.String, mscorlib] ], mscorlib" } ,
23
+ new object [ ] { typeof ( Dictionary < int , List < int > > ) , "System.Collections.Generic.Dictionary`2[[ System.Int32, mscorlib],[ System.Collections.Generic.List`1[[ System.Int32, mscorlib]], mscorlib ]], mscorlib" } ,
23
24
new object [ ] { typeof ( int ) , "System.Int32, mscorlib" } ,
24
- new object [ ] { typeof ( int ? ) , "System.Nullable`1[System.Int32], mscorlib" } ,
25
- new object [ ] { typeof ( KeyValuePair < int , string > ? ) , "System.Nullable`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]], mscorlib" } ,
25
+ new object [ ] { typeof ( int ? ) , "System.Nullable`1[[ System.Int32, mscorlib] ], mscorlib" } ,
26
+ new object [ ] { typeof ( KeyValuePair < int , string > ? ) , "System.Nullable`1[[ System.Collections.Generic.KeyValuePair`2[[ System.Int32, mscorlib],[ System.String, mscorlib]], mscorlib ]], mscorlib" } ,
26
27
new object [ ] { typeof ( int [ ] ) , "System.Int32[], mscorlib" } ,
27
28
new object [ ] { typeof ( int [ , ] ) , "System.Int32[,], mscorlib" } ,
28
29
new object [ ] { typeof ( int [ , ] [ ] ) , "System.Int32[][,], mscorlib" } ,
@@ -33,21 +34,21 @@ public partial class ReflectionExtensionsTest
33
34
new object [ ] { typeof ( int [ , ] [ , , ] [ ] ) , "System.Int32[][,,][,], mscorlib" } ,
34
35
new object [ ] { typeof ( int [ ] [ , , ] [ , ] ) , "System.Int32[,][,,][], mscorlib" } ,
35
36
new object [ ] { typeof ( int [ , ] [ , , ] [ , ] ) , "System.Int32[,][,,][,], mscorlib" } ,
36
- new object [ ] { typeof ( int ? [ ] ) , "System.Nullable`1[System.Int32][], mscorlib" } ,
37
- new object [ ] { typeof ( int ? [ , ] ) , "System.Nullable`1[System.Int32][,], mscorlib" } ,
38
- new object [ ] { typeof ( int ? [ , ] [ ] ) , "System.Nullable`1[System.Int32][][,], mscorlib" } ,
39
- new object [ ] { typeof ( int ? [ ] [ , ] ) , "System.Nullable`1[System.Int32][,][], mscorlib" } ,
40
- new object [ ] { typeof ( int ? [ ] [ ] ) , "System.Nullable`1[System.Int32][][], mscorlib" } ,
41
- new object [ ] { typeof ( int ? [ ] [ ] [ ] ) , "System.Nullable`1[System.Int32][][][], mscorlib" } ,
42
- new object [ ] { typeof ( int ? [ ] [ , , ] [ ] ) , "System.Nullable`1[System.Int32][][,,][], mscorlib" } ,
43
- new object [ ] { typeof ( int ? [ , ] [ , , ] [ ] ) , "System.Nullable`1[System.Int32][][,,][,], mscorlib" } ,
44
- new object [ ] { typeof ( int ? [ ] [ , , ] [ , ] ) , "System.Nullable`1[System.Int32][,][,,][], mscorlib" } ,
45
- new object [ ] { typeof ( int ? [ , ] [ , , ] [ , ] ) , "System.Nullable`1[System.Int32][,][,,][,], mscorlib" } ,
46
- new object [ ] { typeof ( List < int ? > ) , "System.Collections.Generic.List`1[System.Nullable`1[System.Int32]], mscorlib" } ,
47
- new object [ ] { typeof ( List < int ? [ ] > ) , "System.Collections.Generic.List`1[System.Nullable`1[System.Int32][ ]], mscorlib" } ,
48
- new object [ ] { typeof ( List < int ? [ , , ] > ) , "System.Collections.Generic.List`1[System.Nullable`1[System.Int32] [,,]], mscorlib" } ,
49
- new object [ ] { typeof ( List < int ? [ ] [ , , ] > ) , "System.Collections.Generic.List`1[System.Nullable`1[System.Int32] [,,][]], mscorlib" } ,
50
- new object [ ] { typeof ( List < int ? [ , ] [ ] > ) , "System.Collections.Generic.List`1[System.Nullable`1[System.Int32] [][,]], mscorlib" } ,
37
+ new object [ ] { typeof ( int ? [ ] ) , "System.Nullable`1[[ System.Int32, mscorlib] ][], mscorlib" } ,
38
+ new object [ ] { typeof ( int ? [ , ] ) , "System.Nullable`1[[ System.Int32, mscorlib] ][,], mscorlib" } ,
39
+ new object [ ] { typeof ( int ? [ , ] [ ] ) , "System.Nullable`1[[ System.Int32, mscorlib] ][][,], mscorlib" } ,
40
+ new object [ ] { typeof ( int ? [ ] [ , ] ) , "System.Nullable`1[[ System.Int32, mscorlib] ][,][], mscorlib" } ,
41
+ new object [ ] { typeof ( int ? [ ] [ ] ) , "System.Nullable`1[[ System.Int32, mscorlib] ][][], mscorlib" } ,
42
+ new object [ ] { typeof ( int ? [ ] [ ] [ ] ) , "System.Nullable`1[[ System.Int32, mscorlib] ][][][], mscorlib" } ,
43
+ new object [ ] { typeof ( int ? [ ] [ , , ] [ ] ) , "System.Nullable`1[[ System.Int32, mscorlib] ][][,,][], mscorlib" } ,
44
+ new object [ ] { typeof ( int ? [ , ] [ , , ] [ ] ) , "System.Nullable`1[[ System.Int32, mscorlib] ][][,,][,], mscorlib" } ,
45
+ new object [ ] { typeof ( int ? [ ] [ , , ] [ , ] ) , "System.Nullable`1[[ System.Int32, mscorlib] ][,][,,][], mscorlib" } ,
46
+ new object [ ] { typeof ( int ? [ , ] [ , , ] [ , ] ) , "System.Nullable`1[[ System.Int32, mscorlib] ][,][,,][,], mscorlib" } ,
47
+ new object [ ] { typeof ( List < int ? > ) , "System.Collections.Generic.List`1[[ System.Nullable`1[[ System.Int32, mscorlib]], mscorlib ]], mscorlib" } ,
48
+ new object [ ] { typeof ( List < int ? [ ] > ) , "System.Collections.Generic.List`1[[ System.Nullable`1[[ System.Int32, mscorlib]][], mscorlib ]], mscorlib" } ,
49
+ new object [ ] { typeof ( List < int ? [ , , ] > ) , "System.Collections.Generic.List`1[[ System.Nullable`1[[ System.Int32, mscorlib]] [,,], mscorlib ]], mscorlib" } ,
50
+ new object [ ] { typeof ( List < int ? [ ] [ , , ] > ) , "System.Collections.Generic.List`1[[ System.Nullable`1[[ System.Int32, mscorlib]] [,,][], mscorlib ]], mscorlib" } ,
51
+ new object [ ] { typeof ( List < int ? [ , ] [ ] > ) , "System.Collections.Generic.List`1[[ System.Nullable`1[[ System.Int32, mscorlib]] [][,], mscorlib ]], mscorlib" } ,
51
52
new object [ ] { typeof ( ReflectionExtensions ) , "CodeJam.Reflection.ReflectionExtensions, CodeJam" } ,
52
53
new object [ ] { typeof ( int ) . MakePointerType ( ) , "System.Int32*, mscorlib" } ,
53
54
new object [ ] { typeof ( int ) . MakePointerType ( ) . MakeArrayType ( ) , "System.Int32*[], mscorlib" } ,
@@ -58,18 +59,34 @@ public partial class ReflectionExtensionsTest
58
59
new object [ ] { typeof ( int ) . MakeByRefType ( ) , "System.Int32&, mscorlib" } ,
59
60
new object [ ] { typeof ( int [ ] ) . MakeByRefType ( ) , "System.Int32[]&, mscorlib" } ,
60
61
new object [ ] { typeof ( int [ ] [ , ] [ , , ] ) . MakeByRefType ( ) , "System.Int32[,,][,][]&, mscorlib" } ,
61
- new object [ ] { typeof ( int ? [ ] ) . MakeByRefType ( ) , "System.Nullable`1[System.Int32][]&, mscorlib" } ,
62
- new object [ ] { typeof ( int ? [ ] [ , ] ) . MakeByRefType ( ) , "System.Nullable`1[System.Int32][,][]&, mscorlib" } ,
63
- new object [ ] { typeof ( int ? [ , ] [ ] ) . MakeByRefType ( ) , "System.Nullable`1[System.Int32][][,]&, mscorlib" } ,
64
- new object [ ] { typeof ( int ? [ , ] [ ] [ , , ] ) . MakeByRefType ( ) , "System.Nullable`1[System.Int32][,,][][,]&, mscorlib" } ,
65
- new object [ ] { typeof ( int ? [ , ] [ ] [ , , ] ) . MakePointerType ( ) , "System.Nullable`1[System.Int32][,,][][,]*, mscorlib" } ,
66
- new object [ ] { typeof ( int ? ) . MakePointerType ( ) , "System.Nullable`1[System.Int32]*, mscorlib" } ,
67
- new object [ ] { typeof ( int ? ) . MakePointerType ( ) . MakeByRefType ( ) , "System.Nullable`1[System.Int32]*&, mscorlib" } ,
68
- new object [ ] { typeof ( int ? ) . MakePointerType ( ) . MakePointerType ( ) . MakeByRefType ( ) , "System.Nullable`1[System.Int32]**&, mscorlib" } ,
69
- new object [ ] { typeof ( int ? ) . MakeByRefType ( ) , "System.Nullable`1[System.Int32]&, mscorlib" } ,
70
- new object [ ] { typeof ( int ? ) . MakePointerType ( ) . MakeArrayType ( ) , "System.Nullable`1[System.Int32]*[], mscorlib" } ,
71
- new object [ ] { typeof ( int ? ) . MakePointerType ( ) . MakeArrayType ( ) . MakeArrayType ( 2 ) , "System.Nullable`1[System.Int32]*[][,], mscorlib" } ,
72
- new object [ ] { typeof ( int ? ) . MakePointerType ( ) . MakeArrayType ( ) . MakeArrayType ( 2 ) . MakeByRefType ( ) , "System.Nullable`1[System.Int32]*[][,]&, mscorlib" } ,
62
+ new object [ ] { typeof ( int ? [ ] ) . MakeByRefType ( ) , "System.Nullable`1[[System.Int32, mscorlib]][]&, mscorlib" } ,
63
+ new object [ ] { typeof ( int ? [ ] [ , ] ) . MakeByRefType ( ) , "System.Nullable`1[[System.Int32, mscorlib]][,][]&, mscorlib" } ,
64
+ new object [ ] { typeof ( int ? [ , ] [ ] ) . MakeByRefType ( ) , "System.Nullable`1[[System.Int32, mscorlib]][][,]&, mscorlib" } ,
65
+ new object [ ] { typeof ( int ? [ , ] [ ] [ , , ] ) . MakeByRefType ( ) , "System.Nullable`1[[System.Int32, mscorlib]][,,][][,]&, mscorlib" } ,
66
+ new object [ ] { typeof ( int ? [ , ] [ ] [ , , ] ) . MakePointerType ( ) , "System.Nullable`1[[System.Int32, mscorlib]][,,][][,]*, mscorlib" } ,
67
+ new object [ ] { typeof ( int ? ) . MakePointerType ( ) , "System.Nullable`1[[System.Int32, mscorlib]]*, mscorlib" } ,
68
+ new object [ ] { typeof ( int ? ) . MakePointerType ( ) . MakeByRefType ( ) , "System.Nullable`1[[System.Int32, mscorlib]]*&, mscorlib" } ,
69
+ new object [ ] { typeof ( int ? ) . MakePointerType ( ) . MakePointerType ( ) . MakeByRefType ( ) , "System.Nullable`1[[System.Int32, mscorlib]]**&, mscorlib" } ,
70
+ new object [ ] { typeof ( int ? ) . MakeByRefType ( ) , "System.Nullable`1[[System.Int32, mscorlib]]&, mscorlib" } ,
71
+ new object [ ] { typeof ( int ? ) . MakePointerType ( ) . MakeArrayType ( ) , "System.Nullable`1[[System.Int32, mscorlib]]*[], mscorlib" } ,
72
+ new object [ ] { typeof ( int ? ) . MakePointerType ( ) . MakeArrayType ( ) . MakeArrayType ( 2 ) , "System.Nullable`1[[System.Int32, mscorlib]]*[][,], mscorlib" } ,
73
+ new object [ ] { typeof ( int ? ) . MakePointerType ( ) . MakeArrayType ( ) . MakeArrayType ( 2 ) . MakeByRefType ( ) , "System.Nullable`1[[System.Int32, mscorlib]]*[][,]&, mscorlib" } ,
74
+ new object [ ] { typeof ( A ) , "CodeJam.Reflection.ReflectionExtensionsTest+A, CodeJam-Tests" } ,
75
+ new object [ ] { typeof ( A . B ) , "CodeJam.Reflection.ReflectionExtensionsTest+A+B, CodeJam-Tests" } ,
76
+ new object [ ] { typeof ( A . B . C ) , "CodeJam.Reflection.ReflectionExtensionsTest+A+B+C, CodeJam-Tests" } ,
77
+ new object [ ] { typeof ( A < int > ) , "CodeJam.Reflection.ReflectionExtensionsTest+A`1[[System.Int32, mscorlib]], CodeJam-Tests" } ,
78
+ new object [ ] { typeof ( A < int > . B ) , "CodeJam.Reflection.ReflectionExtensionsTest+A`1+B[[System.Int32, mscorlib]], CodeJam-Tests" } ,
79
+ new object [ ] { typeof ( A < int > . B . C < int > ) , "CodeJam.Reflection.ReflectionExtensionsTest+A`1+B+C`1[[System.Int32, mscorlib],[System.Int32, mscorlib]], CodeJam-Tests" } ,
80
+ new object [ ] { typeof ( A < int > . B . C < int ? > ) , "CodeJam.Reflection.ReflectionExtensionsTest+A`1+B+C`1[[System.Int32, mscorlib],[System.Nullable`1[[System.Int32, mscorlib]], mscorlib]], CodeJam-Tests" } ,
81
+ new object [ ] { typeof ( A < int ? > . B . C < int ? > ) , "CodeJam.Reflection.ReflectionExtensionsTest+A`1+B+C`1[[System.Nullable`1[[System.Int32, mscorlib]], mscorlib],[System.Nullable`1[[System.Int32, mscorlib]], mscorlib]], CodeJam-Tests" } ,
82
+ new object [ ] { typeof ( A < int ? [ ] > . B . C < int ? > ) , "CodeJam.Reflection.ReflectionExtensionsTest+A`1+B+C`1[[System.Nullable`1[[System.Int32, mscorlib]][], mscorlib],[System.Nullable`1[[System.Int32, mscorlib]], mscorlib]], CodeJam-Tests" } ,
83
+ new object [ ] { typeof ( A < int ? [ ] > . B . C < int ? > [ ] ) , "CodeJam.Reflection.ReflectionExtensionsTest+A`1+B+C`1[[System.Nullable`1[[System.Int32, mscorlib]][], mscorlib],[System.Nullable`1[[System.Int32, mscorlib]], mscorlib]][], CodeJam-Tests" } ,
84
+ new object [ ] { typeof ( A < int ? [ ] > . B . C < int ? > [ ] ) . MakePointerType ( ) . MakeByRefType ( ) , "CodeJam.Reflection.ReflectionExtensionsTest+A`1+B+C`1[[System.Nullable`1[[System.Int32, mscorlib]][], mscorlib],[System.Nullable`1[[System.Int32, mscorlib]], mscorlib]][]*&, CodeJam-Tests" } ,
85
+ new object [ ] { typeof ( A < int ? [ ] > . B . C < int ? > [ ] ) . MakePointerType ( ) , "CodeJam.Reflection.ReflectionExtensionsTest+A`1+B+C`1[[System.Nullable`1[[System.Int32, mscorlib]][], mscorlib],[System.Nullable`1[[System.Int32, mscorlib]], mscorlib]][]*, CodeJam-Tests" } ,
86
+ new object [ ] { typeof ( A < int ? [ ] > . B . C < int ? > [ ] ) . MakeByRefType ( ) , "CodeJam.Reflection.ReflectionExtensionsTest+A`1+B+C`1[[System.Nullable`1[[System.Int32, mscorlib]][], mscorlib],[System.Nullable`1[[System.Int32, mscorlib]], mscorlib]][]&, CodeJam-Tests" } ,
87
+ new object [ ] { typeof ( A < int ? [ ] > . B . C < A < int ? [ ] > . B . C < int ? > [ ] > [ ] ) , "CodeJam.Reflection.ReflectionExtensionsTest+A`1+B+C`1[[System.Nullable`1[[System.Int32, mscorlib]][], mscorlib],[CodeJam.Reflection.ReflectionExtensionsTest+A`1+B+C`1[[System.Nullable`1[[System.Int32, mscorlib]][], mscorlib],[System.Nullable`1[[System.Int32, mscorlib]], mscorlib]][], CodeJam-Tests]][], CodeJam-Tests" } ,
88
+ new object [ ] { typeof ( A < int ? [ ] > . B . C < A < int ? [ ] > . B . C < int ? > [ ] > [ ] ) . MakeByRefType ( ) , "CodeJam.Reflection.ReflectionExtensionsTest+A`1+B+C`1[[System.Nullable`1[[System.Int32, mscorlib]][], mscorlib],[CodeJam.Reflection.ReflectionExtensionsTest+A`1+B+C`1[[System.Nullable`1[[System.Int32, mscorlib]][], mscorlib],[System.Nullable`1[[System.Int32, mscorlib]], mscorlib]][], CodeJam-Tests]][]&, CodeJam-Tests" } ,
89
+ new object [ ] { typeof ( WithoutNsTestClass ) , "WithoutNsTestClass, CodeJam-Tests" }
73
90
} ;
74
91
75
92
[ Test ]
@@ -94,11 +111,7 @@ public void GetShortAssemblyQualifiedNameTest(Type type, string expected)
94
111
Console . WriteLine ( "Expected: {0}" , regex . Replace ( type . AssemblyQualifiedName ?? "" , "" ) ) ;
95
112
96
113
Assert . AreEqual ( expected , qualifiedName ) ;
97
-
98
- if ( ! type . IsGenericTypeDefinition )
99
- {
100
- Assert . AreEqual ( type , Type . GetType ( qualifiedName ) ) ;
101
- }
114
+ Assert . AreEqual ( type , Type . GetType ( qualifiedName ) ) ;
102
115
}
103
116
104
117
[ TestCase ( typeof ( List < int > ) , typeof ( IList < int > ) , ExpectedResult = true ) ]
@@ -273,5 +286,30 @@ public TestAnonymousCaseAttribute()
273
286
[ TestCase ( typeof ( DateTime ? ) , ExpectedResult = false ) ]
274
287
[ TestCase ( typeof ( DateTime ) , ExpectedResult = false ) ]
275
288
public bool IsAnonymous ( Type type ) => type . IsAnonymous ( ) ;
289
+
290
+ #region Inner types
291
+ private class A
292
+ {
293
+ public class B
294
+ {
295
+ public class C
296
+ {
297
+ }
298
+ }
299
+ }
300
+
301
+ [ SuppressMessage ( "ReSharper" , "UnusedTypeParameter" ) ]
302
+ private class A < TOuter >
303
+ {
304
+ public class B
305
+ {
306
+ public class C < TInner >
307
+ {
308
+ }
309
+ }
310
+ }
311
+ #endregion
276
312
}
277
313
}
314
+
315
+ internal class WithoutNsTestClass { }
0 commit comments