[Mono-dev] typeof(Byte[]).GetInterfacesMap
Jonathan Pryor
jonpryor at vt.edu
Mon May 8 07:50:27 EDT 2006
On Tue, 2006-05-02 at 17:54 -0500, Voigt, Benjamin wrote:
> Would someone please be so kind as to run the following unit test on
> Mono?
A similar test would likely be this:
using System;
using System.Reflection;
class GetInterfaceMap
{
public static void Main ()
{
System.Type baseType = typeof(System.Byte[]);
foreach (System.Type iface in baseType.GetInterfaces())
{
Console.WriteLine(iface.FullName);
Console.WriteLine (baseType.GetInterfaceMap
(iface));
}
}
}
The above test prints out _nothing_. This is because System.Byte[]
doesn't implement any interfaces, rather it's System.Byte[]'s _base_
type which implements all the interfaces, and Mono's
Type.GetInterfaces() method doesn't return the interfaces implemented by
the base type, but just the interfaces implemented by the specified
type.
Perhaps this is a bug (I don't have a .NET runtime to test against),
though it makes sense to me.
If we alter the test slightly to look through System.Byte[]'s _base_
type:
using System;
using System.Reflection;
class GetInterfaceMap
{
public static void Main ()
{
System.Type baseType = typeof(System.Byte[]);
foreach (System.Type iface in
baseType.BaseType.GetInterfaces())
{
Console.WriteLine(iface.FullName);
InterfaceMapping map =
baseType.GetInterfaceMap (iface);
Console.WriteLine("{0} ==> {1}",
map.TargetType, map.InterfaceType);
}
}
}
This produces some actual output:
System.Collections.Generic.IList`1[[System.Byte, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
System.Byte[] ==> System.Collections.Generic.IList`1[System.Byte]
System.Collections.Generic.ICollection`1[[System.Byte, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
System.Byte[] ==> System.Collections.Generic.ICollection`1[System.Byte]
System.Collections.Generic.IEnumerable`1[[System.Byte, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
System.Byte[] ==> System.Collections.Generic.IEnumerable`1[System.Byte]
System.Collections.IEnumerable
System.Byte[] ==> System.Collections.IEnumerable
System.ICloneable
System.Byte[] ==> System.ICloneable
System.Collections.ICollection
System.Byte[] ==> System.Collections.ICollection
System.Collections.IList
System.Byte[] ==> System.Collections.IList
(The above output generated when the test program is compiled with gmcs,
so that .NET 2.0 interfaces are displayed.)
> System.Collections.Generic.IList`1[[System.Byte, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
> TestCase 'M:GetInterfaceMap.ByteArray' failed: Interface not found.
> System.ArgumentException: Interface not found.
> at System.RuntimeTypeHandle.GetFirstSlotForInterface(IntPtr interfaceHandle)
> at System.RuntimeTypeHandle.GetFirstSlotForInterface(RuntimeTypeHandle interfaceHandle)
> at System.RuntimeType.GetInterfaceMap(Type ifaceType)
> Realtime\RealTimeTests\GetInterfaceMap.cs(13,0): at GetInterfaceMap.ByteArray()
>
Mono doesn't generate this exception.
- Jon
More information about the Mono-devel-list
mailing list