예제 #1
0
 public DictionaryMethodDescriptor(DictionaryMethod method, MethodInfoEx methodInfoEx, Type keyType, Type elementType)
 {
     Method = method;
     MethodInfoEx = methodInfoEx;
     KeyType = keyType;
     ElementType = elementType;
 }
예제 #2
0
 public DictionaryMethodDescriptor(DictionaryMethod method, MethodInfoEx methodInfoEx, int keyParameterIndex, int elementParameterIndex)
 {
     Method = method;
     MethodInfoEx = methodInfoEx;
     if (keyParameterIndex >= 0)
         KeyType = MethodInfoEx.MethodInfo.GetParameters()[keyParameterIndex].ParameterType;
     if (elementParameterIndex >= 0)
         ElementType = MethodInfoEx.MethodInfo.GetParameters()[elementParameterIndex].ParameterType;
 }
예제 #3
0
        public static MethodInfoEx GetMethodEx(MethodInfo methodInfo)
        {
            if (!cache.TryGetValue(methodInfo, out var method))
            {
                method = new MethodInfoEx(methodInfo);
                cache.TryAdd(methodInfo, method);
            }

            return(method);
        }
예제 #4
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));
            }
        }
예제 #5
0
 public ListMethodDescriptor(ListMethod method, MethodInfoEx methodInfoEx, int parameterIndex)
 {
     Method       = method;
     MethodInfoEx = methodInfoEx;
     ElementType  = MethodInfoEx.MethodInfo.GetParameters()[parameterIndex].ParameterType;
 }
예제 #6
0
 public ListMethodDescriptor(ListMethod method, MethodInfoEx methodInfoEx, Type elementType)
 {
     Method       = method;
     MethodInfoEx = methodInfoEx;
     ElementType  = elementType;
 }