System.Linq.TypeHelper.FindGenericType C# (CSharp) Метод

FindGenericType() статический приватный Метод

static private FindGenericType ( Type definition, Type type ) : Type
definition Type
type Type
Результат Type
        internal static Type FindGenericType(Type definition, Type type)
        {
            bool? definitionIsInterface = null;
            while (type != null && type != typeof(object))
            {
                TypeInfo typeInfo = type.GetTypeInfo();
                if (typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() == definition)
                    return type;
                if (!definitionIsInterface.HasValue)
                    definitionIsInterface = definition.GetTypeInfo().IsInterface;
                if (definitionIsInterface.GetValueOrDefault())
                {
                    foreach (Type itype in typeInfo.ImplementedInterfaces)
                    {
                        Type found = FindGenericType(definition, itype);
                        if (found != null)
                            return found;
                    }
                }
                type = type.GetTypeInfo().BaseType;
            }
            return null;
        }

Usage Example

        IQueryable IQueryProvider.CreateQuery(System.Linq.Expressions.Expression expression)
        {
            if (expression == null)
            {
                throw System.Linq.Error.ArgumentNull("expression");
            }
            Type type = TypeHelper.FindGenericType(typeof(IQueryable <>), expression.Type);

            if (type == null)
            {
                throw System.Linq.Error.ArgumentNotValid("expression");
            }
            return(EnumerableQuery.Create(type.GetGenericArguments()[0], expression));
        }
All Usage Examples Of System.Linq.TypeHelper::FindGenericType