Esempio n. 1
0
//        public static Type FindInterfaceWith(this Type type1, Type type2)
//        {
//            var array = type2.GetTypesArray().Intersect(type1.GetTypesArray());
//            var typeCurrent = default(Type);
//
//            for(var i = array.Length; i-- > 0;)
//            {
//                if(((typeCurrent = array[i]) == null || typeCurrent.BaseType == null) && i > 0)
//                {
//                    var typeNext = array[i - 1];
//
//                    if(typeNext.FindInterfaceWith(typeCurrent) != typeNext)
//                        return null;
//                    break;
//                }
//            }
//
//            return typeof(object) != typeCurrent ? typeCurrent : null;
//        }
//
        public static Type FindBaseClassWith(this Type type1, Type type2)
        {
            if (null == type1)
            {
                return(type2);
            }

            if (null == type2)
            {
                return(type1);
            }

            for (var currentType2 = type2; currentType2 != null; currentType2 = ReflectionExtensions.GetBaseType(currentType2))
            {
                for (var currentType1 = type1; currentType1 != null; currentType1 = ReflectionExtensions.GetBaseType(currentType1))
                {
                    if (ReflectionExtensions.Equal(currentType2, currentType1))
                    {
                        return(currentType2);
                    }
                }
            }

            return(null);
        }
Esempio n. 2
0
 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);
     }
 }
Esempio n. 3
0
        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);
        }