1
+ using System . Collections ;
2
+ using System . Collections . ObjectModel ;
3
+
4
+ namespace SourceGeneration . Reflection . Test ;
5
+
6
+ [ TestClass ]
7
+ public class GenericEnumerableTypeMemberTest
8
+ {
9
+ [ TestMethod ]
10
+ public void GenericEnumerable ( )
11
+ {
12
+ var typeInfo = SourceReflector . GetRequiredType < GenericEnumerableMemberType > ( ) ;
13
+
14
+ Assert . IsFalse ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . Int ) ) ! . IsGenericEnumerableType ) ;
15
+ Assert . IsFalse ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . Object ) ) ! . IsGenericEnumerableType ) ;
16
+ Assert . IsFalse ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . NonGenericEnumerableInterface ) ) ! . IsGenericEnumerableType ) ;
17
+
18
+ Assert . IsTrue ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . EnumerableInterface ) ) ! . IsGenericEnumerableType ) ;
19
+ Assert . IsTrue ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . ListInterface ) ) ! . IsGenericEnumerableType ) ;
20
+ Assert . IsTrue ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . List ) ) ! . IsGenericEnumerableType ) ;
21
+ Assert . IsTrue ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . ReadOnlyCollection ) ) ! . IsGenericEnumerableType ) ;
22
+ Assert . IsTrue ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . CustomList ) ) ! . IsGenericEnumerableType ) ;
23
+ Assert . IsTrue ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . CustomCollection ) ) ! . IsGenericEnumerableType ) ;
24
+ Assert . IsTrue ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . CustomEnumerable ) ) ! . IsGenericEnumerableType ) ;
25
+
26
+ Assert . IsFalse ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . EnumerableInterface ) ) ! . IsGenericDictionaryType ) ;
27
+ Assert . IsFalse ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . ListInterface ) ) ! . IsGenericDictionaryType ) ;
28
+ Assert . IsFalse ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . List ) ) ! . IsGenericDictionaryType ) ;
29
+ Assert . IsFalse ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . ReadOnlyCollection ) ) ! . IsGenericDictionaryType ) ;
30
+ Assert . IsFalse ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . CustomList ) ) ! . IsGenericDictionaryType ) ;
31
+ Assert . IsFalse ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . CustomCollection ) ) ! . IsGenericDictionaryType ) ;
32
+ Assert . IsFalse ( typeInfo . GetFieldOrProperty ( nameof ( GenericEnumerableMemberType . CustomEnumerable ) ) ! . IsGenericDictionaryType ) ;
33
+ }
34
+ }
35
+
36
+ [ SourceReflection ]
37
+ public class GenericEnumerableMemberType
38
+ {
39
+ public object ? Object { get ; set ; }
40
+ public int Int { get ; set ; }
41
+ public IEnumerable < string > ? EnumerableInterface { get ; set ; }
42
+ public IList < string > ? ListInterface { get ; set ; }
43
+ public List < string > ? List { get ; set ; }
44
+ public ReadOnlyCollection < string > ? ReadOnlyCollection { get ; set ; }
45
+ public IEnumerable ? NonGenericEnumerableInterface { get ; set ; }
46
+
47
+ public CustomList ? CustomList ;
48
+ public CustomCollection ? CustomCollection ;
49
+ public CustomEnumerable ? CustomEnumerable ;
50
+ }
51
+
52
+ public class CustomList : CustomCollection , IList < int >
53
+ {
54
+ public int this [ int index ] { get => throw new NotImplementedException ( ) ; set => throw new NotImplementedException ( ) ; }
55
+
56
+ public int IndexOf ( int item )
57
+ {
58
+ throw new NotImplementedException ( ) ;
59
+ }
60
+
61
+ public void Insert ( int index , int item )
62
+ {
63
+ throw new NotImplementedException ( ) ;
64
+ }
65
+
66
+ public void RemoveAt ( int index )
67
+ {
68
+ throw new NotImplementedException ( ) ;
69
+ }
70
+ }
71
+
72
+ public class CustomCollection : ICollection < int >
73
+ {
74
+ public int Count => throw new NotImplementedException ( ) ;
75
+
76
+ public bool IsReadOnly => throw new NotImplementedException ( ) ;
77
+
78
+ public void Add ( int item )
79
+ {
80
+ throw new NotImplementedException ( ) ;
81
+ }
82
+
83
+ public void Clear ( )
84
+ {
85
+ throw new NotImplementedException ( ) ;
86
+ }
87
+
88
+ public bool Contains ( int item )
89
+ {
90
+ throw new NotImplementedException ( ) ;
91
+ }
92
+
93
+ public void CopyTo ( int [ ] array , int arrayIndex )
94
+ {
95
+ throw new NotImplementedException ( ) ;
96
+ }
97
+
98
+ public IEnumerator < int > GetEnumerator ( )
99
+ {
100
+ throw new NotImplementedException ( ) ;
101
+ }
102
+
103
+ public bool Remove ( int item )
104
+ {
105
+ throw new NotImplementedException ( ) ;
106
+ }
107
+
108
+ IEnumerator IEnumerable . GetEnumerator ( )
109
+ {
110
+ return GetEnumerator ( ) ;
111
+ }
112
+ }
113
+ public class CustomEnumerable : IEnumerable < int >
114
+ {
115
+ public IEnumerator < int > GetEnumerator ( )
116
+ {
117
+ throw new NotImplementedException ( ) ;
118
+ }
119
+
120
+ IEnumerator IEnumerable . GetEnumerator ( )
121
+ {
122
+ return GetEnumerator ( ) ;
123
+ }
124
+ }
0 commit comments