Esempio n. 1
0
        private ParameterTypesRating GetParameterTypesRating(List <SignatureType> searchParameterTypes)
        {
            var parameterRating = new ParameterTypesRating();

            if (ParameterTypes.Count == 0 && searchParameterTypes.Count == 0)
            {
                parameterRating.AddExactMatch();
            }

            if (ParameterTypes.Count < searchParameterTypes.Count)
            {
                return(parameterRating.SetFailed());
            }

            parameterRating.SetGenericParameterCount(ParameterTypes.Count(p => p.IsGeneric));

            for (var i = 0; i < ParameterTypes.Count; i++)
            {
                var thisType = this.ParameterTypes[i];

                if (searchParameterTypes.Count > i)
                {
                    var otherType = searchParameterTypes[i];

                    if (otherType.FoundMatchingType == thisType.FoundMatchingType || otherType.FoundMatchingType == typeof(NullObject))
                    {
                        parameterRating.AddExactMatch();
                        continue;
                    }

                    if (thisType.FoundMatchingType.IsInterface && TypeHelpers.ImplementsInterface(otherType.FoundMatchingType, thisType.FoundMatchingType))
                    {
                        parameterRating.AddCastableMatch();
                        continue;
                    }

                    if (TypeHelpers.IsImplicitCastableTo(otherType.FoundMatchingType, thisType.FoundMatchingType))
                    {
                        parameterRating.AddCastableMatch();
                        continue;
                    }

                    if (TypeHelpers.InheritFromClass(otherType.FoundMatchingType, thisType.FoundMatchingType, true, false))
                    {
                        parameterRating.AddInheritanceLevel(TypeHelpers.InheritFromClassLevel(otherType.FoundMatchingType, thisType.FoundMatchingType));
                        continue;
                    }

                    return(parameterRating.SetFailed());
                }

                if (!thisType.IsOptional)
                {
                    return(parameterRating.SetFailed());
                }
            }

            return(parameterRating);
        }
Esempio n. 2
0
        internal MethodInfoRating SetParameterTypesRating(ParameterTypesRating rating)
        {
            ParameterTypesMismatch = rating;
            if (rating.Failed)
            {
                Failed = true;
            }

            return(this);
        }