public static bool ExecuteGenericMethod(object obj, Type type, string methodName, bool isStatic, Type[] arguments, Type[] variableType, object[] parameters, out object result)
        {
            result = null;

            var res = InformationOnTheTypes.FindGenericMethodsWithGenericArguments(type, isStatic, methodName, arguments, variableType);

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

            try
            {
                result = res.Invoke(obj, parameters);

                if (result != null && res.ReturnType.GetTypeInfo().IsInterface)
                {
                    result = new AutoWrap(result, res.ReturnType);
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
示例#2
0
        public object InvokeWithDefaultParameters(object target, object[] input, int parametersCount)
        {
            if (input.Length == parametersCount)
            {
                return(Invoke(target, input));
            }
            object[]        parametersValue = new object[parametersCount];
            ParameterInfo[] parameters      = Method.GetParameters();
            Array.Copy(input, parametersValue, input.Length);

            for (int i = input.Length; i < parameters.Length; i++)
            {
                parametersValue[i] = parameters[i].RawDefaultValue;
            }

            var res = Invoke(target, parametersValue);

            Array.Copy(parametersValue, input, input.Length);

            if (res != null && ReturnType != null)
            {
                res = new AutoWrap(res, ReturnType);
            }
            return(res);
        }
        public int Add(AutoWrap obj)
        {
            var element = new StorageElem(obj);
            var gotLock = false;

            try
            {
                _lockObject.Enter(ref gotLock);

                if (FirstDeleted == -1)
                {
                    return(AddInArray(element));
                }
                else
                {
                    int newPos = FirstDeleted;
                    FirstDeleted      = _elements[newPos].Next;
                    _elements[newPos] = element;
                    return(newPos);
                }
            }
            finally
            {
                if (gotLock)
                {
                    _lockObject.Exit();
                }
            }
        }
        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);
        }
        public static bool ExecuteExtensionMethod(AutoWrap autoWrap, string methodName, object[] parameters, out object result)
        {
            result = null;
            if (autoWrap.IsType)
            {
                if (methodName == "GetTypeInfo")
                {
                    result = autoWrap.Type.GetTypeInfo();
                    return(true);
                }

                return(false);
            }

            var assembly = autoWrap.Type.GetTypeInfo().Assembly;
            var types    = GetExtensionMethods(assembly, autoWrap.Type, methodName);

            if (CheckExtensionMethods(types, autoWrap, methodName, parameters, out result))
            {
                return(true);
            }

            if (autoWrap.Type.IsGenericTypeOf(_enumerableType.GetTypeInfo(), _enumerableType))
            {
                types = FindType(_linqExtensionTypes, autoWrap.Type, methodName, (method) => method.IsGenericMethod);
                return(CheckExtensionMethods(types, autoWrap, methodName, parameters, out result));
            }

            return(false);
        }
示例#6
0
        public static object JsonToArray(object typeOrig, string data, int rank = 0)
        {
            Type type      = TypeForCreateObject(typeOrig);
            Type typeArray = null;

            typeArray = rank > 0 ? type.MakeArrayType(rank) : type.MakeArrayType();

            return(AutoWrap.WrapObject(JsonConvert.DeserializeObject(data, typeArray)));
        }
        object IPropertyOrFieldInfo.GetValue(object obj)
        {
            var res = PropertyInfo.GetValue(obj);

            if (res != null && ReturnType != null)
            {
                res = new AutoWrap(res, ReturnType);
            }
            return(res);
        }
        public GenericExecutor(AutoWrap wrap, object[] arguments)
        {
            _arguments = new Type[arguments.Length];

            for (int i = 0; i < arguments.Length; i++)
            {
                _arguments[i] = NetObjectToNative.FindTypeForCreateObject(arguments[i]);
            }

            _wrap = wrap;
        }
示例#9
0
        // Обернем объекты для посылки на сервер
        // Напрямую передаются только числа, строки, DateTime, Guid, byte[]
        public static object WrapObject(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            if (!ServerRPC.WorkWithVariant.MatchTypes.ContainsKey(obj.GetType()))
            {
                obj = new AutoWrap(obj);
            }

            return(obj);
        }
        public IEnumerator GetEnumerator()
        {
            foreach (var str in _enumerator)
            {
                object res = null;
                if (str != null && _typeInfo.IsInstanceOfType(str))
                {
                    res = new AutoWrap(str, _type);
                }

                yield return(res);
            }
        }
示例#11
0
        public object ExecuteMethod(object Target, object[] input)
        {
            if (!(HasParams || HasDefaultValue))
            {
                return(Invoke(Target, input));
            }

            int parametersCount = (ParamsCount > 0) ? ParamsCount : ParametersCount;

            if (HasDefaultValue)
            {
                return(InvokeWithDefaultParameters(Target, input, parametersCount));
            }

            int lastParameterIndex = parametersCount - 1;

            object[] realParams = new object[parametersCount];
            for (int i = 0; i < lastParameterIndex; i++)
            {
                realParams[i] = input[i];
            }

            Array parameters = Array.CreateInstance(TypeParams, input.Length - lastParameterIndex);

            for (int i = 0; i < parameters.Length; i++)
            {
                parameters.SetValue(input[i + lastParameterIndex], i);
            }

            realParams[lastParameterIndex] = parameters;

            var res = Invoke(Target, realParams);

            parameters = (Array)realParams[lastParameterIndex];
            for (int i = 0; i < parameters.Length; i++)
            {
                input[i + lastParameterIndex] = parameters.GetValue(i);
            }
            if (res != null && ReturnType != null)
            {
                res = new AutoWrap(res, ReturnType);
            }
            return(res);
        }
示例#12
0
 internal StorageElem(AutoWrap wrap)
 {
     Wrap = wrap;
     Next = -1;
 }
示例#13
0
 public static object JsonToObject(object typeOrig, string data) =>
 AutoWrap.WrapObject(JsonConvert.DeserializeObject(data, TypeForCreateObject(typeOrig)));
 // Нужен для получения типа неподдерживаемого 1С, беззнаковые,Decimal итд
 public static Object ChangeType(object type, object valueOrig) =>
 new AutoWrap(
     Convert.ChangeType(AutoWrap.GetRalObject(valueOrig),
                        FindTypeForCreateObject(type),
                        CultureInfo.InvariantCulture));
 public static Object ToInt(object valueOrig) => new AutoWrap(Convert.ChangeType(
                                                                  AutoWrap.GetRalObject(valueOrig),
                                                                  typeof(Int32),
                                                                  CultureInfo.InvariantCulture));
 public static object CreateObject(object type) =>
 AutoWrap.WrapObject(System.Activator.CreateInstance(FindTypeForCreateObject(type)));
示例#17
0
 internal StorageElem(AutoWrap wrap, int next)
 {
     Wrap = wrap;
     Next = next;
 }