public static void GetInterfacesCollectionStupid(this Type node, ICollection <Type> result) { if (node == null) { return; } GetInterfacesCollectionStupid(ReflectionExtensions.GetBaseType(node), result); if (node.IsInterface) { result.Add(node); } foreach (var interfaCe in ReflectionExtensions.GetInterfaces(node)) { result.Add(interfaCe); } }
public static Type[] GetTypesArray(this Type node) { if (node == null) { return(Type.EmptyTypes); } var baseArray = ReflectionExtensions.GetBaseType(node).GetTypesArray(); var interfaces = ReflectionExtensions.GetInterfaces(node).Subtract(baseArray); var index = interfaces.Length + baseArray.Length; var typeArray = new Type[1 + index]; typeArray[index] = node; Array.Sort(interfaces, interfaces.CoverageComparison()); Array.Copy(interfaces, 0, typeArray, index - interfaces.Length, interfaces.Length); Array.Copy(baseArray, typeArray, baseArray.Length); return(typeArray); }
private static Comparison <Type> CoverageComparison(this Type[] az) { return ((tx, ty) => { var ay = ReflectionExtensions.GetInterfaces(ty); var ax = ReflectionExtensions.GetInterfaces(tx); var overlapped = az.GetOverlappedCount(ax).CompareTo(az.GetOverlappedCount(ay)); if (overlapped != 0) { return overlapped; } var occurrence = az.GetOccurrenceCount(tx).CompareTo(az.GetOccurrenceCount(ty)); return occurrence != 0 ? occurrence : 0; }); }
public Type[] GetInterfaces() { return(SubstituteGenericParameters(ReflectionExtensions.GetInterfaces(m_type), m_type.GetGenericArguments(), m_inst)); }
private static int GetOccurrenceCount(this Type[] ax, Type ty) { return(Array.FindAll(ax, x => Array.Exists(ReflectionExtensions.GetInterfaces(x), tx => ReflectionExtensions.Equal(tx, ty))).Length); }