/// <summary> /// 构造自定义类 填充Object委托 /// </summary> /// <param name="reader"></param> /// <param name="type">要填充的类型</param> /// <returns></returns> public static DegFullCustomObjNoT CreateDegFullCustomObj(IDataReader reader, Type type) { string key = string.Format("{0}{1}", type.FullName, FullDataHelper.GetDataReaderInfo(reader)); Delegate degMethod; if (_idiFullCustomObj_noT.TryGetValue(key, out degMethod)) { return((DegFullCustomObjNoT)degMethod); } DegFullCustomObjNoT deg = null; //构造填充方法 DynamicMethod method = FullDataHelper.CreateFullObjMethod(reader, type, false, false); //为动态方法构造调用委托 deg = (DegFullCustomObjNoT)method.CreateDelegate(typeof(DegFullCustomObjNoT)); if (!_idiFullCustomObj_noT.ContainsKey(key)) { _idiFullCustomObj_noT.Add(key, deg); } return(deg); }
/// <summary> /// 构造自定义类 填充List委托 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="reader"></param> /// <returns></returns> public static DegFullCustomList <T> CreateDegFullCustomList <T>(IDataReader reader) { string key = string.Format("{0}{1}", typeof(T).FullName, FullDataHelper.GetDataReaderInfo(reader)); Delegate degMethod; if (_idiFullCustomList.TryGetValue(key, out degMethod)) { return((DegFullCustomList <T>)degMethod); } DegFullCustomList <T> deg = null; //构造填充方法 DynamicMethod method = FullDataHelper.CreateFullListMethod(reader, typeof(T), false); //为动态方法构造调用委托 deg = (DegFullCustomList <T>)method.CreateDelegate(typeof(DegFullCustomList <T>)); if (!_idiFullCustomList.ContainsKey(key)) { _idiFullCustomList.TryAdd(key, deg); } return(deg); }