Beispiel #1
0
 public static object[] convertParams(MethodBase methodBase, Dictionary <string, string> jsonNamedParams)
 {
     ParameterInfo[] paramInfos = methodBase.GetParameters();
     if (paramInfos.Length != jsonNamedParams.Count)
     {
         return(null);
     }
     object[] ret = new object[paramInfos.Length];
     for (int i = 0; i < paramInfos.Length; i++)
     {
         ParameterInfo pi = paramInfos[i];
         if (!jsonNamedParams.ContainsKey(pi.Name))
         {
             return(null);
         }
         ret[i] = TypeConvertUtils.Convert(pi.ParameterType, jsonNamedParams[pi.Name]);
     }
     return(ret);
 }
Beispiel #2
0
 public static object[] convertParams(MethodBase methodBase, string[] jsonParams)
 {
     ParameterInfo[] paramInfos = methodBase.GetParameters();
     if (paramInfos.Length != jsonParams.Length)
     {
         return(null);
     }
     object[] ret = new object[paramInfos.Length];
     for (int i = 0; i < paramInfos.Length; i++)
     {
         ParameterInfo pi = paramInfos[i];
         try
         {
             ret[i] = TypeConvertUtils.Convert(pi.ParameterType, jsonParams[i]);
         }
         catch
         {
             return(null);
         }
     }
     return(ret);
 }
Beispiel #3
0
        public void setPropertyValue(object instance, string propertyName, object[] index, string jsonValue)
        {
            //   Type type = instance.GetType();
            PropertyInfo prop = type.GetProperty(propertyName);

            if (prop != null)
            {
                object value = TypeConvertUtils.Convert(prop.PropertyType, jsonValue);
                prop.SetValue(instance, value, index);
                return;
            }

            FieldInfo fld = type.GetField(propertyName);

            if (fld != null)
            {
                object value = TypeConvertUtils.Convert(fld.FieldType, jsonValue);
                fld.SetValue(instance, value);
                return;
            }

            throw new XException("不能发现属性成员" + propertyName);
        }