Esempio n. 1
0
 static bool ParameterCompatibleWithTypeConstraint(Type parameter, Type constraint)
 {
     return(constraint.IsAssignableFrom(parameter) ||
            Traverse.Across(parameter, p => p.BaseType)
            .Concat(parameter.GetInterfaces())
            .Any(p => ParameterEqualsConstraint(p, constraint)));
 }
Esempio n. 2
0
        private static bool ParameterCompatibleWithTypeConstraint(Type parameter, Type constraint)
        {
            if (constraint.GetTypeInfo().IsAssignableFrom(parameter.GetTypeInfo()))
            {
                return(true);
            }

            var allGenericParametersMatch = false;
            var baseType = parameter.GetTypeInfo().BaseType ?? parameter;

            if (!constraint.GetTypeInfo().IsInterface&&
                baseType.GetTypeInfo().IsGenericType&&
                baseType.GenericTypeArguments.Length > 0 &&
                baseType.GenericTypeArguments.Length == constraint.GenericTypeArguments.Length)
            {
                allGenericParametersMatch = true;
                for (int i = 0; i < baseType.GenericTypeArguments.Length; i++)
                {
                    var paramArg               = baseType.GenericTypeArguments[i];
                    var constraintArg          = constraint.GenericTypeArguments[i];
                    var constraintArgIsGeneric = constraintArg.GetTypeInfo().IsGenericType;

                    allGenericParametersMatch &= paramArg.IsClosedTypeOf(constraintArgIsGeneric ? constraintArg.GetGenericTypeDefinition() : constraintArg);
                }
            }

            return(allGenericParametersMatch ||
                   Traverse.Across(parameter, p => p.GetTypeInfo().BaseType)
                   .Concat(parameter.GetTypeInfo().ImplementedInterfaces)
                   .Any(p => ParameterEqualsConstraint(p, constraint)));
        }
Esempio n. 3
0
 private static bool ParameterCompatibleWithTypeConstraint(Type parameter, Type constraint)
 {
     return(constraint.GetTypeInfo().IsAssignableFrom(parameter.GetTypeInfo()) ||
            Traverse.Across(parameter, p => p.GetTypeInfo().BaseType)
            .Concat(parameter.GetTypeInfo().ImplementedInterfaces)
            .Any(p => ParameterEqualsConstraint(p, constraint)));
 }
Esempio n. 4
0
        static bool ParameterCompatibleWithTypeConstraint(Type parameter, Type constraint)
        {
            return(constraint.IsAssignableFrom(parameter) ||
                   Traverse.Across(parameter, p => p.BaseType)
                   .Concat(parameter.GetInterfaces())
#if !(WINDOWS_PHONE)
                   .Any(p => p.GUID.Equals(constraint.GUID)));
Esempio n. 5
0
        static IEnumerable <Type> TypesAssignableFrom(Type candidateType)
        {
            return(candidateType.GetInterfaces().Concat(
#if !ASPNETCORE50
                       Traverse.Across(candidateType, t => t.BaseType)));
#else
                       Traverse.Across(candidateType, t => t.GetTypeInfo().BaseType));
#endif
        }
Esempio n. 6
0
        static bool ParameterCompatibleWithTypeConstraint(Type parameter, Type constraint)
        {
            return(constraint.IsAssignableFrom(parameter) ||
#if !ASPNETCORE50
                   Traverse.Across(parameter, p => p.BaseType)
#else
                   Traverse.Across(parameter, p => p.GetTypeInfo().BaseType)
#endif
                   .Concat(parameter.GetInterfaces())
                   .Any(p => ParameterEqualsConstraint(p, constraint)));
        }
Esempio n. 7
0
 static IEnumerable <Type> TypesAssignableFrom(Type candidateType)
 {
     return(candidateType.GetInterfaces().Concat(
                Traverse.Across(candidateType, t => t.BaseType)));
 }
Esempio n. 8
0
 private static IEnumerable <Type> TypesAssignableFrom(Type candidateType)
 {
     return(candidateType.GetTypeInfo().ImplementedInterfaces.Concat(
                Traverse.Across(candidateType, t => t.GetTypeInfo().BaseType)));
 }
Esempio n. 9
0
 private static bool ParameterCompatibleWithTypeConstraint(Type parameter, Type constraint)
 {
     return(constraint.IsAssignableFrom(parameter) || Traverse.Across <Type>(parameter, p => p.BaseType).Concat <Type>(parameter.GetInterfaces()).Any <Type>(p => p.GUID.Equals(constraint.GUID)));
 }