public InterfaceMapping GetInterfaceMap(Type interfaceType)
{
CheckBaked();
InterfaceMapping map = new InterfaceMapping();
if (!IsDirectlyImplementedInterface(interfaceType))
{
Type baseType = this.BaseType;
if (baseType == null)
{
throw new ArgumentException();
}
else
{
map = baseType.GetInterfaceMap(interfaceType);
}
}
else
{
map.InterfaceMethods = interfaceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
map.InterfaceType = interfaceType;
map.TargetMethods = new MethodInfo[map.InterfaceMethods.Length];
FillInExplicitInterfaceMethods(map.InterfaceMethods, map.TargetMethods);
MethodInfo[] methods = GetMethods(BindingFlags.Instance | BindingFlags.Public);
for (int i = 0; i < map.TargetMethods.Length; i++)
{
if (map.TargetMethods[i] == null)
{
// TODO use proper method resolution (also take into account that no implicit base class implementation is used across assembly boundaries)
for (int j = 0; j < methods.Length; j++)
{
if (methods[j].Name == map.InterfaceMethods[i].Name
&& methods[j].MethodSignature.Equals(map.InterfaceMethods[i].MethodSignature))
{
map.TargetMethods[i] = methods[j];
}
}
}
}
for (Type baseType = this.BaseType; baseType != null && interfaceType.IsAssignableFrom(baseType); baseType = baseType.BaseType)
{
baseType.FillInExplicitInterfaceMethods(map.InterfaceMethods, map.TargetMethods);
}
}
map.TargetType = this;
return map;
}