示例#1
0
        public static void GetIndex(BinaryReader br, BinaryWriter bw)
        {
            if (!GetAW(br, bw, out var autoWrap))
            {
                return;
            }

            var    parameters = GetArrayParams(br);
            string methodName = "get_Item";

            if (typeof(Array).IsAssignableFrom(autoWrap.Type))
            {
                methodName = "GetValue";
            }

            var changeParams = new List <int>();
            var res          = autoWrap.TryInvokeMember(methodName, parameters, out var result, changeParams, out var error);

            if (!res)
            {
                SetError(error, bw);
            }
            else
            {
                bw.Write(true);
                WorkWithVariant.WriteObject(AutoWrap.WrapObject(result), bw);
            }
        }
示例#2
0
        public static void IteratorNext(BinaryReader br, BinaryWriter bw)
        {
            if (!GetAW(br, bw, out var autoWrap))
            {
                return;
            }

            try
            {
                var enumerator = (System.Collections.IEnumerator)autoWrap.Object;
                var res        = enumerator.MoveNext();
                bw.Write(true);
                if (!res)
                {
                    AutoWrap.ObjectsList.RemoveKey(autoWrap.IndexInStorage);
                    bw.Write(false);
                    return;
                }

                bw.Write(true);
                WorkWithVariant.WriteObject(AutoWrap.WrapObject(enumerator.Current), bw);
            }
            catch (Exception e)
            {
                SetError(AutoWrap.GetExceptionString("Ошибка итератора", "", e), bw);
            }
        }
示例#3
0
        public static bool CallAsFuncAll(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    args       = GetArrayParams(br);

            List <int> changeParameters = new List <int>();

            var res = autoWrap.TryInvokeMember(methodName, args, out result, changeParameters, out var error);

            if (!res)
            {
                SetError(error, bw);
                return(false);
            }

            if (writeResult)
            {
                bw.Write(true);
                WorkWithVariant.WriteObject(AutoWrap.WrapObject(result), bw);
                WriteChangeParams(bw, args, changeParameters);
            }
            return(true);
        }
示例#4
0
        public static void CallAsDelegate(BinaryReader br, BinaryWriter bw)
        {
            object result;

            if (!GetAW(br, bw, out var autoWrap))
            {
                return;
            }

            var args = GetArrayParams(br);

            try
            {
                var del = (Delegate)autoWrap.Object;
                result = del.DynamicInvoke(args);
            }
            catch (Exception e)
            {
                SetError(AutoWrap.GetExceptionString($"Ошибка вызова делегата Target = ", "", e), bw);
                return;
            }

            bw.Write(true);
            WorkWithVariant.WriteObject(AutoWrap.WrapObject(result), bw);
        }
示例#5
0
        private static void WriteChangeParams(BinaryWriter bw, object[] args, List <int> changeParameters)
        {
            bw.Write(changeParameters.Count);

            foreach (var i in changeParameters)
            {
                bw.Write(i);
                WorkWithVariant.WriteObject(AutoWrap.WrapObject(args[i]), bw);
            }
        }
示例#6
0
        internal void SendAsyncMessage(bool successfully, object result)
        {
            MemoryStream stream = new MemoryStream();
            var          bw     = new BinaryWriter(stream);

            bw.Write((byte)0);
            bw.Write(_key.ToByteArray());
            bw.Write(successfully);
            WorkWithVariant.WriteObject(AutoWrap.WrapObject(result), bw);
            bw.Flush();

            SendStream(stream);
        }
示例#7
0
        public static void GetPropVal(BinaryReader br, BinaryWriter bw)
        {
            if (!GetAW(br, bw, out var autoWrap))
            {
                return;
            }

            string propertyName = br.ReadString();
            var    res          = autoWrap.TryGetMember(propertyName, out var result, out var error);

            if (!res)
            {
                SetError(error, bw);
                return;
            }

            bw.Write(true);
            WorkWithVariant.WriteObject(AutoWrap.WrapObject(result), bw);
        }
示例#8
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);
            }
        }
示例#9
0
        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);
        }
 public static object CreateObject(object type) =>
 AutoWrap.WrapObject(System.Activator.CreateInstance(FindTypeForCreateObject(type)));