Beispiel #1
0
        public object Invoke(string methodName, IEnumerable <object> arguments = null)
        {
            MethodInfoEx method = null;

            if (MethodsByName.TryGetValue(methodName, out var methods))
            {
                if (methods.Count > 1)
                {
                    method = methods.First();
                }
                else
                {
                    if (!arguments.Any(x => x == null))
                    {
                        method = methods.Where(x => x.MethodInfo.HasSignature(arguments.Select(y => y.GetType()))).FirstOrDefault();
                    }

                    if (method == null)
                    {
                        //Best match
                        var matches = methods.Where(x => x.MethodInfo.IsInvokableWith(arguments)).ToList();

                        if (matches.Count == 1)
                        {
                            method = matches.First();
                        }
                        else if (matches.Count > 1)
                        {
                            throw new AmbiguousMatchException("More than one possible matches for " + methodName + " found in Type" + WrappedObject.GetType());
                        }
                    }
                }
            }

            if (method == null)
            {
                throw new MissingMethodException("Method " + methodName + " does not exist in Type " + WrappedObject.GetType());
            }
            else
            {
                return(method.Invoke(WrappedObject, arguments));
            }
        }
Beispiel #2
0
 public object Invoke(string methodName, IEnumerable <Type> signature, IEnumerable <object> arguments)
 {
     if (MethodsByName.TryGetValue(methodName, out var methods))
     {
         var method = methods.Where(x => x.MethodInfo.HasSignature(signature)).FirstOrDefault();
         if (method == null)
         {
             throw new MissingMethodException("Method " + methodName + "with given signature does not exist in Type " + WrappedObject.GetType());
         }
         else
         {
             return(method.Invoke(WrappedObject, arguments));
         }
     }
     else
     {
         throw new MissingMethodException("Method " + methodName + " does not exist in Type " + WrappedObject.GetType());
     }
 }