public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { var methodName = binder.Name; var typesParameters = AllMethodsForName.GetTypesParameters(args); var obj = _wrap.IsType ? null : _wrap.Object; var type = _wrap.Type; var isStatic = _wrap.IsType; if (ExecuteGenericMethod(obj, type, methodName, isStatic, _arguments, typesParameters, args, out result)) { return(true); } // Проверим методы расширения if (!isStatic) { if (ExtensionMethod.ExecuteExtensionMethodGenericType(obj, methodName, _arguments, typesParameters, args, out result)) { return(true); } } return(false); }
public AllMethodsForName FindAllMethodByName(string methodName) { CheckForSynonym(ref methodName); if (!Methods.TryGetValue(methodName, out var methods)) { var methodInfos = _type.GetTypeInfo().GetMethods().Where(x => x.Name == methodName).ToArray(); if (methodInfos.Length == 0) { return(null); } methods = new AllMethodsForName(methodInfos); Methods[methodName] = methods; } return(methods); }
public static bool CallAsGenericFuncAll(BinaryReader br, BinaryWriter bw, out object result, bool writeResult) { result = null;; if (!GetAW(br, bw, out var autoWrap)) { return(false); } string methodName = br.ReadString(); var arguments = GetArrayParams(br); var Params = GetArrayParams(br); // Можно параметры передавать ввиде типов и строк var genericArguments = new Type[arguments.Length]; for (int i = 0; i < genericArguments.Length; i++) { genericArguments[i] = NetObjectToNative.FindTypeForCreateObject(arguments[i]); } result = null; var typesOfParameters = AllMethodsForName.GetTypesParameters(Params); var res = InformationOnTheTypes.FindGenericMethodsWithGenericArguments( autoWrap.Type, autoWrap.IsType, methodName, genericArguments, typesOfParameters); if (res == null) { SetError("Не найден дженерик метод " + methodName, bw); return(false); } try { var copyParams = new object[Params.Length]; Params.CopyTo(copyParams, 0); var obj = autoWrap.IsType ? null : autoWrap.Object; result = res.ExecuteMethod(obj, copyParams); var returnType = res.Method.ReturnType; if (result != null && returnType.GetTypeInfo().IsInterface) { result = new AutoWrap(result, returnType); } if (writeResult) { bw.Write(true); WorkWithVariant.WriteObject(AutoWrap.WrapObject(result), bw); WriteChangeParams(bw, copyParams, AutoWrap.GetChangeParams(Params, copyParams)); } } catch (Exception e) { SetError(AutoWrap.GetExceptionString($"Ошибка вызова Дженерик метода {methodName}", "", e), bw); return(false); } return(true); }