public DictionaryMethodDescriptor(DictionaryMethod method, MethodInfoEx methodInfoEx, Type keyType, Type elementType) { Method = method; MethodInfoEx = methodInfoEx; KeyType = keyType; ElementType = elementType; }
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; }
public static MethodInfoEx GetMethodEx(MethodInfo methodInfo) { if (!cache.TryGetValue(methodInfo, out var method)) { method = new MethodInfoEx(methodInfo); cache.TryAdd(methodInfo, method); } return(method); }
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)); } }
public ListMethodDescriptor(ListMethod method, MethodInfoEx methodInfoEx, int parameterIndex) { Method = method; MethodInfoEx = methodInfoEx; ElementType = MethodInfoEx.MethodInfo.GetParameters()[parameterIndex].ParameterType; }
public ListMethodDescriptor(ListMethod method, MethodInfoEx methodInfoEx, Type elementType) { Method = method; MethodInfoEx = methodInfoEx; ElementType = elementType; }