/// <summary> /// 空间名称得到方法的clazz Dic /// </summary> /// <param name="classForName"></param> /// <returns></returns> public static Dictionary <string, Clazz> MethodToLowerFunction(string classForName) { //classForName = "YanBo_CG.Zjd.ZjdPo.Jtcy2"; Dictionary <string, Clazz> dic = new Dictionary <string, Clazz>(); Type type = Type.GetType(classForName); dynamic obj = type.Assembly.CreateInstance(classForName); MethodInfo[] ms = type.GetMethods(); Clazz clazz; foreach (MethodInfo m in ms) { ParameterInfo[] ps = m.GetParameters(); if (ps.Length == 0) { continue; } //得到方法的名字 String methodName = m.Name.Replace("set_", ""); //去掉set,第一个字母大写 methodName = methodName.ToLower(); //都只有一个参数,得到参数类型 Type pt = ps[0].ParameterType; clazz = new Clazz(); clazz.setFunction(methodName); clazz.setParamterType(pt); //List<MethodInfo> list = new List<MethodInfo>(); //list.Add(m); // clazz.setMethodInfos(list); clazz.SetMethodInfo = m; clazz.setFullClassName(classForName); clazz.SetMethodInfo = m; dic.Add(methodName, clazz); } foreach (MethodInfo m in ms) { ParameterInfo[] ps = m.GetParameters(); if (ps.Length != 0) { continue; } //得到方法的名字 String methodName = m.Name.Replace("get_", ""); //去掉set,第一个字母大写 methodName = methodName.ToLower(); if (dic.TryGetValue(methodName, out clazz)) { // clazz.getMethodInfos().Add(m); clazz.GetMethodInfo = m; } } return(dic); }
/// <summary> /// 映射列数 和clazz /// </summary> /// <param name="dic"></param> /// <returns></returns> public static Dictionary <String, Clazz> GetRealClazzDicValue(Dictionary <String, String> dic) { String fullName; Dictionary <String, Clazz> calzzDic = null; Clazz clazz = new Clazz(); if (dic.TryGetValue("类的全名称", out fullName)) { calzzDic = MethodToLowerFunction(fullName); } //转换成小写的值 dic = Utils.ValueToLower(dic); Dictionary <String, String> .KeyCollection keys = dic.Keys; Dictionary <String, Clazz> newCalzzDic = ChangeValue <String, Clazz>(dic, calzzDic); clazz.setFullClassName(fullName); newCalzzDic.Add("类的全名称", clazz); return(newCalzzDic); }
public static Dictionary <string, Clazz> MethodToFunction(string classForName) { Dictionary <string, Clazz> dic; if (ReflectDicCache.TryGetValue(classForName, out dic)) { return(dic); } dic = new Dictionary <string, Clazz>(); Type type = Type.GetType(classForName); dynamic obj = type.Assembly.CreateInstance(classForName); MethodInfo[] ms = type.GetMethods(); Clazz clazz; foreach (MethodInfo m in ms) { ParameterInfo[] ps = m.GetParameters(); if (ps.Length == 0) { continue; } //得到方法的名字 String methodName = m.Name.Replace("set_", ""); if (methodName.Equals("Equals")) { continue; } //都只有一个参数,得到参数类型 Type pt = ps[0].ParameterType; clazz = new Clazz(); clazz.setFunction(methodName); clazz.setParamterType(pt); /* List<MethodInfo> list = new List<MethodInfo>(); * list.Add(m); * clazz.setMethodInfos(list); */ clazz.SetMethodInfo = m; clazz.setFullClassName(classForName); if (!dic.Keys.Contains(methodName)) { dic.Add(methodName, clazz); } } foreach (MethodInfo m in ms) { ParameterInfo[] ps = m.GetParameters(); if (ps.Length != 0) { continue; } //得到方法的名字 String methodName = m.Name.Replace("get_", ""); if (methodName.Equals("Equals")) { continue; } if (dic.TryGetValue(methodName, out clazz)) { //clazz.getMethodInfos().Add(m); clazz.GetMethodInfo = m; } } ReflectDicCache.Add(classForName, dic); return(dic); }