示例#1
0
        public bool TryInvokeMember(string name, object[] argsOrig, out object result, List <int> changedParameters, out string error)
        {
            error = null;
            if (IndexInStorage == 0 && name == "ОчиститьСсылку")
            {
                if (argsOrig[0] is AutoWrap temp)
                {
                    ObjectsList.RemoveKey(temp.IndexInStorage);
                }
                result = null;
                return(true);
            }

            result = null;
            object[] args = GetArrayRealObjects(argsOrig);

            try
            {
                object obj;
                if (IsDynamic)
                {
                    obj = DynamicInvoker.InvokeMember(Object, name, args);
                }
                else
                {
                    var method = InformationOnTheTypes.FindMethod(Type, IsType, name, args);

                    if (method == null)
                    {
                        if (name == "_as")
                        {
                            obj = NetObjectToNative.GetInterface(Object, args[0]);
                        }
                        else if (!ExtensionMethod.ExecuteExtensionMethod(this, name, args, out obj) &&
                                 !ExecuteInterfaceMethodAsObject(name, args, out obj, ref error))
                        {
                            error += " Не найден метод " + name;
                            return(false);
                        }
                    }
                    else
                    {
                        obj = method.ExecuteMethod(IsType ? null : Object, args);
                    }
                }
                SetChangeInArgs(argsOrig, args, changedParameters);
                result = obj;
            }
            catch (Exception e)
            {
                error = GetExceptionString("методе", name, e);

                return(false);
            }

            // Так как параметры могут изменяться (OUT) и передаются по ссылке
            // нужно обратно обернуть параметры

            return(true);
        }
示例#2
0
        private static bool CheckExtensionMethods(Type[] types, AutoWrap autoWrap, string methodName, object[] parameters,
                                                  out object result)
        {
            result = null;
            if (types.Length == 0)
            {
                return(false);
            }

            var args = new object[parameters.Length + 1];

            Array.Copy(parameters, 0, args, 1, parameters.Length);
            args[0] = autoWrap.Object;
            foreach (var type in types)
            {
                try
                {
                    var method = InformationOnTheTypes.FindMethod(type, true, methodName, args);
                    if (method != null)
                    {
                        result = method.ExecuteMethod(null, args);
                        Array.Copy(args, 1, parameters, 0, parameters.Length);

                        return(true);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            return(false);
        }
示例#3
0
        private bool ExecuteInterfaceMethodAsObject(string name, object[] args, out object result, ref string Error)
        {
            result = null;
            Error  = null;
            if (!(IsType || Type.GetTypeInfo().IsInterface))
            {
                return(false);
            }

            RpcMethodInfo method = InformationOnTheTypes.FindMethod(Object.GetType(), false, name, args);

            if (method == null)
            {
                return(false);
            }

            try
            {
                result = method.ExecuteMethod(Object, args);
                return(true);
            }
            catch (Exception e)
            {
                Error += GetExceptionString("методе", name, e);
            }
            return(false);
        }
示例#4
0
        public static void CallAsyncFunc(BinaryReader br, BinaryWriter bw, IPAddress address)
        {
            if (!CallAsFuncAll(br, bw, out var result, false))
            {
                return;
            }
            try
            {
                var taskId   = new Guid(br.ReadBytes(16));
                var port     = br.ReadInt32();
                var typeInfo = result.GetType().GetTypeInfo();

                var asyncCallBack = new TcpAsyncCallBack(taskId, address, port);
                var callBack      = new Action <bool, object>(asyncCallBack.SendAsyncMessage);
                if (!typeInfo.IsGenericType)
                {
                    AsyncRunner.TaskExecute((Task)result, callBack);
                    return;
                }

                var args   = new[] { result, callBack };
                var method = InformationOnTheTypes.FindMethod(typeof(AsyncRunner), true, "Execute", args);

                if (method == null)
                {
                    SetError("Неверный результат", bw);
                    return;
                }

                method.ExecuteMethod(null, args);
            }
            catch (Exception e)
            {
                SetError(AutoWrap.GetExceptionString("Ошибка вызова делегата", "", e), bw);
                return;
            }

            bw.Write(true);
            WorkWithVariant.WriteObject(null, bw);
        }
示例#5
0
        private static void CallStaticMethod(BinaryWriter bw, Type T, string methodName, object[] args)
        {
            try
            {
                var method = InformationOnTheTypes.FindMethod(T, true, methodName, args);

                if (method == null)
                {
                    SetError($"Нет найден метод  {method} для типа {T}", bw);
                    return;
                }

                var obj = method.ExecuteMethod(null, args);

                bw.Write(true);
                WorkWithVariant.WriteObject(AutoWrap.WrapObject(obj), bw);
                bw.Write((int)0);
            }
            catch (Exception e)
            {
                SetError(AutoWrap.GetExceptionString("Ошибка бинарной операции ", "", e), bw);
            }
        }