Why do the following assertions fail (IsAssignableFrom
returns true
):
Assert.False(typeof(IList<UInt16>).IsAssignableFrom(typeof(Int16[]))
Assert.False(typeof(IList<Int16>).IsAssignableFrom(typeof(UInt16[]))
Assert.False(typeof(IList<UInt32>).IsAssignableFrom(typeof(Int32[]))
Assert.False(typeof(IList<Int32>).IsAssignableFrom(typeof(UInt32[]))
Assert.False(typeof(IList<UInt64>).IsAssignableFrom(typeof(Int64[]))
Assert.False(typeof(IList<Int64>).IsAssignableFrom(typeof(UInt64[]))
I would have expected them to fail (IsAssignableFrom
should returns false
) because this results in a compiler error:
IList<UInt16> x = new Int16[]{}; // CS0029 Cannot implictly convert ...
IList<Int16> x = new UInt16[]{}; // CS0029 Cannot implictly convert ...
IList<UInt32> x = new Int32[]{}; // CS0029 Cannot implictly convert ...
IList<Int32> x = new UInt32[]{}; // CS0029 Cannot implictly convert ...
IList<UInt64> x = new Int64[]{}; // CS0029 Cannot implictly convert ...
IList<Int64> x = new UInt64[]{}; // CS0029 Cannot implictly convert ...
For bytes the behavior is different, the assertions pass (IsAssignableFrom
actually returns false
).
Assert.False(typeof(IList<Byte>).IsAssignableFrom(typeof(SByte[]))
Assert.False(typeof(IList<SByte>).IsAssignableFrom(typeof(Byte[]))
Aucun commentaire:
Enregistrer un commentaire