Exemplo n.º 1
0
        private bool IsValidExtensionType(IType actualType, IType extensionType, IExtensionEnabled extension)
        {
            if (TypeCompatibilityRules.IsAssignableFrom(extensionType, actualType))
            {
                return(true);
            }

            // Check for a valid generic extension
            IMethod method = extension as IMethod;

            if (method == null || method.GenericInfo == null)
            {
                return(false);
            }

            System.Collections.Generic.List <IGenericParameter> genericParameters = new System.Collections.Generic.List <IGenericParameter>(GenericsServices.FindGenericParameters(extensionType));
            if (genericParameters.Count == 0)
            {
                return(false);
            }

            TypeInferrer inferrer = new TypeInferrer(genericParameters);

            inferrer.Infer(extensionType, actualType);
            return(inferrer.FinalizeInference());
        }
Exemplo n.º 2
0
        public virtual bool CanBeReachedByDowncast(IType expectedType, IType actualType)
        {
            if (actualType.IsFinal)
            {
                return(false);
            }

            if (IsDuckType(actualType))
            {
                return(true);
            }

            if (!IsDowncastAllowed())
            {
                return(false);
            }

            if (expectedType.IsInterface || actualType.IsInterface)
            {
                return(CanBeReachedByInterfaceDowncast(expectedType, actualType));
            }

            return(TypeCompatibilityRules.IsAssignableFrom(actualType, expectedType));
        }