private object GetOverload(Type[] sig, IList<MethodBase> targets, bool wrapCtors) {
            // We can still end up with more than one target since generic and non-generic
            // methods can share the same name and signature. So we'll build up a new
            // reflected method with all the candidate targets. A caller can then index this
            // reflected method if necessary in order to provide generic type arguments and
            // fully disambiguate the target.

            // Search for targets with the right number of arguments.
            BuiltinFunction bf;
            BuiltinFunction.TypeList tl = new BuiltinFunction.TypeList(sig);
            lock (_function.OverloadDictionary) {
                if (!_function.OverloadDictionary.TryGetValue(tl, out bf)) {
                    MethodBase[] newTargets = FindMatchingTargets(sig, targets);

                    if (targets == null)
                        throw ScriptingRuntimeHelpers.SimpleTypeError(String.Format("No match found for the method signature {0}", sig));    // TODO: Sig to usable display

                    _function.OverloadDictionary[tl] = bf = new BuiltinFunction(_function.Name, newTargets, Function.DeclaringType, _function.FunctionType);
                }
            }

            if (_instance != null) {
                return bf.BindToInstance(_instance);
            } else if (wrapCtors) {
                return GetTargetFunction(bf);
            } else {
                return bf;
            }
        }
Esempio n. 2
0
        private object GetOverload(Type[] sig, IList <MethodBase> targets, bool wrapCtors)
        {
            // We can still end up with more than one target since generic and non-generic
            // methods can share the same name and signature. So we'll build up a new
            // reflected method with all the candidate targets. A caller can then index this
            // reflected method if necessary in order to provide generic type arguments and
            // fully disambiguate the target.

            BuiltinFunction bf;

            BuiltinFunction.TypeList tl = new BuiltinFunction.TypeList(sig);
            lock (_function.OverloadDictionary) {
                if (!_function.OverloadDictionary.TryGetValue(tl, out bf))
                {
                    MethodBase[] newTargets = FindMatchingTargets(sig, targets, true);

                    if (newTargets.Length == 0)
                    {
                        // If no overload was found, check also using CodeContext for backward compatibility
                        newTargets = FindMatchingTargets(sig, targets, false);
                    }

                    if (newTargets.Length == 0)
                    {
                        ThrowOverloadException(sig, targets);
                    }
                    else
                    {
                        _function.OverloadDictionary[tl] = bf = new BuiltinFunction(_function.Name, newTargets, Function.DeclaringType, _function.FunctionType);
                    }
                }
            }

            if (_instance != null)
            {
                return(bf.BindToInstance(_instance));
            }
            else if (wrapCtors)
            {
                return(GetTargetFunction(bf));
            }
            else
            {
                return(bf);
            }
        }
Esempio n. 3
0
        private object GetOverload(Type[] sig, IList <MethodBase> targets, bool wrapCtors)
        {
            // We can still end up with more than one target since generic and non-generic
            // methods can share the same name and signature. So we'll build up a new
            // reflected method with all the candidate targets. A caller can then index this
            // reflected method if necessary in order to provide generic type arguments and
            // fully disambiguate the target.

            // Search for targets with the right number of arguments.
            BuiltinFunction bf;

            BuiltinFunction.TypeList tl = new BuiltinFunction.TypeList(sig);
            lock (_function.OverloadDictionary) {
                if (!_function.OverloadDictionary.TryGetValue(tl, out bf))
                {
                    MethodBase[] newTargets = FindMatchingTargets(sig, targets);

                    if (targets == null)
                    {
                        throw ScriptingRuntimeHelpers.SimpleTypeError(String.Format("No match found for the method signature {0}", sig));    // TODO: Sig to usable display
                    }
                    _function.OverloadDictionary[tl] = bf = new BuiltinFunction(_function.Name, newTargets, Function.DeclaringType, _function.FunctionType);
                }
            }

            if (_instance != null)
            {
                return(bf.BindToInstance(_instance));
            }
            else if (wrapCtors)
            {
                return(GetTargetFunction(bf));
            }
            else
            {
                return(bf);
            }
        }