private static void initParameterDictionary(Type objClass, object source, Dictionary <object, object> retParametersDictionary, string paramType) { try { FieldInfo[] declaredField = objClass.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); int i = 0; for (i = 0; i < declaredField.Length; i++) { FieldInfo field = declaredField[i]; string methodName = "get" + field.Name.Substring(0, 1).ToUpper() + field.Name.Substring(1); string fieldName = field.Name; MethodInfo[] methods = objClass.GetMethods(); int k = 0; for (k = 0; k < methods.Length; k++) { MethodInfo m = methods[k]; if (m.Name.Equals(methodName, StringComparison.CurrentCultureIgnoreCase)) { ParamAttribute attribute = (ParamAttribute)ParamAttribute.GetCustomAttribute(m, typeof(ParamAttribute)); if (attribute == null) { continue; } if (!"".Equals(attribute.paramName)) { fieldName = attribute.paramName; } if (paramType.Equals(attribute.paramType)) { setParameterToDictionary(m, source, retParametersDictionary, fieldName); } else if (paramType.Equals(attribute.paramType)) { setParameterToDictionary(m, source, retParametersDictionary, fieldName); } else if (paramType.Equals(attribute.paramType)) { setParameterToDictionary(m, source, retParametersDictionary, fieldName); } else if ("".Equals(paramType)) { setParameterToDictionary(m, source, retParametersDictionary, fieldName); } } } } } catch (Exception e) { throw new Exception(e.Message); } }
private static Boolean initParameter(object o, FieldInfo[] declaredField, Type objType, object targetObj) { Boolean hasParam = false; int i = 0; for (i = 0; i < declaredField.Length; i++) { FieldInfo field = declaredField[i]; string methodField = field.Name.Substring(0, 1).ToUpper() + field.Name.Substring(1); string getMethodName = field.GetType() == typeof(Boolean) ? "is" + methodField : "get" + methodField; string setMethodName = "set" + methodField; MethodInfo[] methods = objType.GetMethods(); int k = 0; for (k = 0; k < methods.Length; k++) { MethodInfo m = methods[k]; if (m.Name.Equals(getMethodName)) { ParamAttribute attribute = (ParamAttribute)ParamAttribute.GetCustomAttribute(m, typeof(ParamAttribute)); if (attribute == null) { continue; } string dataKey = attribute.paramName.ToString().ToLower(); if (o.ToString().IndexOf(dataKey) != -1 && o.ToString().IndexOf(":") != -1) { hasParam = true; object data = toObject(o, dataKey); MethodInfo setM = objType.GetMethod(setMethodName); setParameterToMap(setM, targetObj, field, data); } } } } return(hasParam); }