コード例 #1
0
ファイル: Types.cs プロジェクト: Gotcha7770/CS.Edu
        public static bool IsSubclassOf(this Type type, GenericType baseType)
        {
            while (type != null && type != CLRRootType)
            {
                if (type.IsGenericType)
                {
                    if (type.GetGenericTypeDefinition() == baseType.GenericTypeDefinition)
                    {
                        return(true);
                    }
                }

                type = type.BaseType;
            }

            return(false);
        }
コード例 #2
0
ファイル: Types.cs プロジェクト: Gotcha7770/CS.Edu
 public static bool IsSubclassOf(this object obj, GenericType baseType)
 {
     return(obj.GetType().IsSubclassOf(baseType));
 }
コード例 #3
0
ファイル: Types.cs プロジェクト: Gotcha7770/CS.Edu
        public static bool TryConvert(Type type, out GenericType result)
        {
            result = CanConvertFrom(type) ? (GenericType)type : null;

            return(result != null);
        }
コード例 #4
0
ファイル: Types.cs プロジェクト: Gotcha7770/CS.Edu
 public static bool IsSubclassOfGeneric(this Type type, Type baseType) //???
 {
     return(GenericType.CanConvertFrom(baseType) &&
            type.IsSubclassOf((GenericType)baseType));
 }
コード例 #5
0
ファイル: Enumerables.cs プロジェクト: Gotcha7770/CS.Edu
        public static IEnumerable <T> OfType <T>(this IEnumerable <T> source)
        {
            var genericType = new GenericType(typeof(T));

            return(source.Where(x => x.IsSubclassOf(genericType)));
        }