Beispiel #1
0
        public FunctionType GetMatchingOverload(Type[] argTypes, ArgumentParameterSpecificity specificity = ArgumentParameterSpecificity.ArgumentMoreSpecific)
        {
            var overloads = Overloads.Prepend(this);

            foreach (var o in overloads)
            {
                // in case this overload is an operator overload that expects a this arg
                if (o.ExpectsThisArg)
                {
                    argTypes = argTypes.Skip(1).ToArray();
                }

                if (!ParameterListDiffers(o.Parameters.Select(p => p.Type), argTypes, specificity))
                {
                    return(o);
                }
            }
            return(null);
        }
Beispiel #2
0
        public static bool ParameterListDiffers(IEnumerable <Type> _argsParent, IEnumerable <Type> _argsChild, ArgumentParameterSpecificity specificity = ArgumentParameterSpecificity.ArgumentMoreSpecific)
        {
            var argsParent = _argsParent.ToArray();
            var argsChild  = _argsChild.ToArray();

            if (argsChild.Length != argsParent.Length)
            {
                return(true);
            }

            for (var i = 0; i < argsChild.Length; ++i)
            {
                if (argsChild[i].FullName != argsParent[i].FullName)
                {
                    var typeParam = argsChild[i] as InheritableType;
                    var typeArg   = argsParent[i] as InheritableType;

                    if (typeParam == null || typeArg == null)
                    {
                        return(true);
                    }

                    var argInhParam = InheritableType.IsDescendantOf(typeParam, typeArg);
                    var paramInhArg = InheritableType.IsDescendantOf(typeArg, typeParam);

                    switch (specificity)
                    {
                    case ArgumentParameterSpecificity.ArgumentMoreSpecific: return(!argInhParam);

                    case ArgumentParameterSpecificity.ParameterMoreSpecific: return(!paramInhArg);

                    case ArgumentParameterSpecificity.Bidirectional: return(!(argInhParam || paramInhArg));
                    }
                }
            }

            return(false);
        }
Beispiel #3
0
 public FunctionType GetMatchingOverload(Expressions.Nodes.Functions.ArgumentsNode.Argument[] args, ArgumentParameterSpecificity specificity = ArgumentParameterSpecificity.ArgumentMoreSpecific)
 {
     return(GetMatchingOverload(args.Select(a => a.Expression.ReturnType).ToArray(), specificity));
 }