public AstGenericMethodWithTypeArguments(IAstMethodReference actual, IList<IAstTypeReference> typeArguments, GenericTypeHelper genericHelper)
        {
            Argument.RequireNotNull("actual", actual);
            Argument.RequireNotNull("typeArguments", typeArguments);

            this.Actual = actual;
            this.GenericArgumentTypes = typeArguments.AsReadOnly();

            var genericParameterTypes = actual.GetGenericParameterTypes().ToArray();
            this.ParameterTypes = actual.ParameterTypes.Select(t => ApplyArgumentTypes(genericHelper, t, genericParameterTypes)).ToArray().AsReadOnly();
            this.ReturnType = ApplyArgumentTypes(genericHelper, actual.ReturnType, genericParameterTypes);
        }
Esempio n. 2
0
        public AstGenericMethodWithTypeArguments(IAstMethodReference actual, IList <IAstTypeReference> typeArguments, GenericTypeHelper genericHelper)
        {
            Argument.RequireNotNull("actual", actual);
            Argument.RequireNotNull("typeArguments", typeArguments);

            this.Actual = actual;
            this.GenericArgumentTypes = typeArguments.AsReadOnly();

            var genericParameterTypes = actual.GetGenericParameterTypes().ToArray();

            this.ParameterTypes = actual.ParameterTypes.Select(t => ApplyArgumentTypes(genericHelper, t, genericParameterTypes)).ToArray().AsReadOnly();
            this.ReturnType     = ApplyArgumentTypes(genericHelper, actual.ReturnType, genericParameterTypes);
        }
        private IAstMethodReference CoerceToType(IAstMethodReference function, IAstFunctionTypeReference functionType)
        {
            var genericParameterTypes      = function.GetGenericParameterTypes().ToArray();
            var genericArgumentTypes       = new IAstTypeReference[genericParameterTypes.Length];
            var functionTypeParameterTypes = functionType.GetParameterTypes().ToArray();
            var functionParameterTypes     = (function.ParameterTypes as IList <IAstTypeReference>) ?? function.ParameterTypes.ToArray();

            for (var i = 0; i < genericArgumentTypes.Length; i++)
            {
                var parameterIndex = functionParameterTypes.IndexOf(genericParameterTypes[i]);
                genericArgumentTypes[i] = functionTypeParameterTypes[parameterIndex];
            }

            return(new AstGenericMethodWithTypeArguments(function, genericArgumentTypes, this.genericHelper));
        }
Esempio n. 4
0
        private Tuple<IAstMethodReference, int> GetOrMakeMatch(IAstMethodReference method, IEnumerable<IAstTypeReference> parameterTypes, IEnumerable<IAstTypeReference> argumentTypes)
        {
            var genericTheories = new Dictionary<IAstTypeReference, ISet<IAstTypeReference>>();
            var distance = GetDistanceForAll(method, parameterTypes, argumentTypes, genericTheories);
            if (distance == -1)
                return null;

            if (method.IsGeneric) {
                var genericParameters = method.GetGenericParameterTypes().ToArray();
                var genericArguments = new IAstTypeReference[genericParameters.Length];
                for (var i = 0; i < genericParameters.Length; i++) {
                    var theories = genericTheories.GetValueOrDefault(genericParameters[i]);
                    if (theories == null)
                        return null;

                    var aggregate = ReconcileGenericTheories(theories, method);
                    if (aggregate == null)
                        return null;

                    genericArguments[i] = aggregate;
                }

                var generic = new AstGenericMethodWithTypeArguments(method, genericArguments, this.genericHelper);
                return Tuple.Create((IAstMethodReference)generic, distance);
            }

            return Tuple.Create(method, distance);
        }