2 using System
.Collections
;
3 using System
.Collections
.Generic
;
15 public static class CollectionTester
17 static int Test
<T
> (IList
<T
> list
)
22 ICollection
<T
> collection
= list
;
23 if (collection
.Count
!= 1)
26 IEnumerable
<T
> enumerable
= list
;
27 IEnumerator
<T
> enumerator
= enumerable
.GetEnumerator ();
28 if (!enumerator
.MoveNext ())
30 if (enumerator
.MoveNext ())
36 public static int Test ()
39 X
[] xarray
= new X
[] { new X () }
;
42 result
= Test
<X
> (xarray
);
46 result
= Test
<object> (xarray
);
50 result
= Test
<Y
> (xarray
);
56 int[] iarray
= new int [] { 5 }
;
57 result
= Test
<int> (iarray
);
61 result
= Test
<uint> ((IList
<uint>) (object) iarray
);
65 uint[] uiarray
= new uint [] { 5 }
;
66 result
= Test
<int> ((IList
<int>) (object) uiarray
);
70 result
= Test
<uint> (uiarray
);
76 long[] larray
= new long [] { 5 }
;
77 result
= Test
<long> (larray
);
81 result
= Test
<ulong> ((IList
<ulong>) (object) larray
);
85 ulong[] ularray
= new ulong [] { 5 }
;
86 result
= Test
<long> ((IList
<long>) (object) ularray
);
90 result
= Test
<ulong> (ularray
);
96 short[] sarray
= new short [] { 5 }
;
97 result
= Test
<short> (sarray
);
101 result
= Test
<ushort> ((IList
<ushort>) (object) sarray
);
105 ushort[] usarray
= new ushort [] { 5 }
;
106 result
= Test
<short> ((IList
<short>) (object) usarray
);
110 result
= Test
<ushort> (usarray
);
116 byte[] barray
= new byte [] { 5 }
;
117 result
= Test
<byte> (barray
);
121 result
= Test
<sbyte> ((IList
<sbyte>) (object) barray
);
125 sbyte[] sbarray
= new sbyte [] { 5 }
;
126 result
= Test
<byte> ((IList
<byte>) (object) sbarray
);
130 result
= Test
<sbyte> (sbarray
);
139 public static class InterfaceTester
141 public const bool Debug
= false;
143 static readonly Type ilist_type
;
144 static readonly Type icollection_type
;
145 static readonly Type ienumerable_type
;
146 static readonly Type generic_ilist_type
;
147 static readonly Type generic_icollection_type
;
148 static readonly Type generic_ienumerable_type
;
149 static readonly Type icloneable_type
;
151 static InterfaceTester ()
153 ilist_type
= typeof (IList
);
154 icollection_type
= typeof (ICollection
);
155 ienumerable_type
= typeof (IEnumerable
);
156 generic_ilist_type
= typeof (IList
<>);
157 generic_icollection_type
= typeof (ICollection
<>);
158 generic_ienumerable_type
= typeof (IEnumerable
<>);
159 icloneable_type
= typeof (ICloneable
);
168 static int Test (Type t
, params Type
[] iface_types
)
170 Hashtable ifaces
= new Hashtable ();
171 ifaces
.Add (ilist_type
, State
.Missing
);
172 ifaces
.Add (icollection_type
, State
.Missing
);
173 ifaces
.Add (ienumerable_type
, State
.Missing
);
174 ifaces
.Add (icloneable_type
, State
.Missing
);
175 ifaces
.Add (typeof (IStructuralEquatable
), State
.Missing
);
176 ifaces
.Add (typeof (IStructuralComparable
), State
.Missing
);
177 Type array_type
= t
.MakeArrayType ();
180 Console
.WriteLine ("Checking {0}", t
);
181 foreach (Type iface
in t
.GetInterfaces ())
182 Console
.WriteLine (" {0}", iface
);
185 foreach (Type iface
in iface_types
) {
186 Type
[] gargs
= new Type
[] { iface }
;
187 ifaces
.Add (generic_ilist_type
.MakeGenericType (gargs
), State
.Missing
);
188 ifaces
.Add (generic_icollection_type
.MakeGenericType (gargs
), State
.Missing
);
189 ifaces
.Add (generic_ienumerable_type
.MakeGenericType (gargs
), State
.Missing
);
192 ifaces
.Add (typeof (IReadOnlyCollection
<>).MakeGenericType (gargs
), State
.Missing
);
193 ifaces
.Add (typeof (IReadOnlyList
<>).MakeGenericType (gargs
), State
.Missing
);
197 foreach (Type iface
in array_type
.GetInterfaces ()) {
198 if (ifaces
.Contains (iface
))
199 ifaces
[iface
] = State
.Found
;
201 ifaces
.Add (iface
, State
.Extra
);
206 foreach (Type iface
in ifaces
.Keys
) {
207 State state
= (State
) ifaces
[iface
];
208 if (state
== State
.Found
) {
210 Console
.WriteLine ("Found {0}", iface
);
214 Console
.WriteLine ("ERROR: {0} {1}", iface
, state
);
220 Console
.WriteLine ();
225 public static int Test ()
227 int result
= Test (typeof (X
), typeof (X
));
231 result
= Test (typeof (Y
), typeof (Y
));
235 result
= Test (typeof (DateTime
), typeof (DateTime
));
239 result
= Test (typeof (float), typeof (float));
243 result
= Test (typeof (int), typeof (int));
247 result
= Test (typeof (uint), typeof (uint));
251 result
= Test (typeof (long), typeof (long));
255 result
= Test (typeof (ulong), typeof (ulong));
259 result
= Test (typeof (short), typeof (short));
263 result
= Test (typeof (ushort), typeof (ushort));
267 result
= Test (typeof (Foo
), typeof (Foo
));
269 return 1000 + result
;
280 result
= CollectionTester
.Test ();
283 result
= InterfaceTester
.Test ();
285 return 10000 + result
;
289 public static int Main ()
291 int result
= Test ();
293 Console
.WriteLine ("OK");
295 Console
.WriteLine ("ERROR: {0}", result
);