Exemplo n.º 1
0
        private object getMetodParametersValues(ParameterInfo parameter, InvokeData data, ParamsData paramsData)
        {
            var value = getMetodParametersValuesByInvoke(parameter, data, paramsData);

            if (value == null || string.IsNullOrWhiteSpace(value.ToString()))
            {
                value = getTypeDefaultValue(parameter);
            }
            return(value);
        }
Exemplo n.º 2
0
        public object InvokeMethod(InvokeData data)
        {
            var args = getMetodParametersValues(data);

            if (data.Method.IsStatic)
            {
                var result = data.Method.Invoke(null, args);
                return(result);
            }
            else
            {
                var result = data.Method.Invoke(data.Impl, args);
                return(result);
            }
        }
Exemplo n.º 3
0
        private ParamsData getMetod1Param(InvokeData data)
        {
            var parameters = data.Method.GetParameters();
            var result     = new ParamsData();
            var param1Name = string.Empty;

            result.ParamsCount = parameters.Length;
            foreach (var parameter in parameters)
            {
                if (isActionParameter(parameter))
                {
                    result.ParamsCount--;
                    continue;
                }
                try
                {
                    var flag = getMetodParameterValueByName(parameter, data.NameParams, out object value);
                    if (flag)
                    {
                        result.ParamsCount--;
                        continue;
                    }
                }
                catch (Exception ex)
                {
                }
                try
                {
                    var flag = getMetodParameterValueByType(parameter, data.TypeParams, out object value);
                    if (flag)
                    {
                        result.ParamsCount--;
                        continue;
                    }
                }
                catch (Exception ex)
                {
                }
                param1Name = parameter.Name;
            }

            if (result.ParamsCount == 1)
            {
                result.Param1Name = param1Name;
            }

            return(result);
        }
Exemplo n.º 4
0
 private object getMetodParametersValuesByInvoke(ParameterInfo parameter, InvokeData data, ParamsData paramsData)
 {
     try
     {
         var flag = getMetodParameterValue(parameter, data.ParamsJson, out object value);
         if (flag && value != null && !string.IsNullOrWhiteSpace(value.ToString()))
         {
             return(value);
         }
     }
     catch (Exception ex)
     {
     }
     try
     {
         var flag = getMetodParameterValueByName(parameter, data.NameParams, out object value);
         if (flag)
         {
             return(value);
         }
     }
     catch (Exception ex)
     {
     }
     try
     {
         var flag = getMetodParameterValueByType(parameter, data.TypeParams, out object value);
         if (flag)
         {
             return(value);
         }
     }
     catch (Exception ex)
     {
     }
     try
     {
         var flag = getMetodParamsCount1Value(parameter, paramsData, data.ParamsJson, out object value);
         if (flag)
         {
             return(value);
         }
     }
     catch (Exception ex)
     {
     }
     return(null);
 }
Exemplo n.º 5
0
        private object[] getMetodParametersValues(InvokeData data)
        {
            var paramData  = getMetod1Param(data);
            var parameters = data.Method.GetParameters();
            var result     = new List <object>();

            foreach (var parameter in parameters)
            {
                if (isActionParameter(parameter))
                {
                    result.Add(data.CallbackAction);
                    continue;
                }
                result.Add(getMetodParametersValues(parameter, data, paramData));
            }
            return(result.ToArray());
        }
Exemplo n.º 6
0
        private object mInvoke(object impl, string methodName, string param, Dictionary <string, string> nameParams, IList <object> typeParams, Action <object> callback)
        {
            var data = new InvokeData();

            data.Impl   = impl;
            data.Method = getMethod(data.Impl, methodName);
            if (param != null)
            {
                data.ParamsJson = param;
            }
            data.NameParams = createNameParams();
            if (nameParams != null)
            {
                foreach (var k in nameParams.Keys)
                {
                    if (data.NameParams.ContainsKey(k))
                    {
                        data.NameParams[k] = nameParams[k];
                        continue;
                    }
                    var v = nameParams[k];
                    data.NameParams.Add(k, v);
                }
            }
            if (typeParams != null)
            {
                data.TypeParams = typeParams;
            }
            if (callback != null)
            {
                data.CallbackAction = callback;
            }
            var result = InvokeRunner.Instance.InvokeMethod(data);

            return(result);
        }