internal static T ExecuteGetCookie <T>(HttpRequestBase httpRequest, string cookieName, Dictionary <string, object> propertyDict, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { HttpCookie httpCookie = GetHttpCookie(httpRequest, cookieName); if (httpCookie == null) { return(null); } Dictionary <PropertyInfo, string> mapperDict = CommonHelper.InitPropertyReadMapper <T, CookieTAttribute>(propertyDict, (name) => httpCookie.Values[name] != null); dynamic propertySetDict = null; if (reflectionType != ReflectionTypeEnum.Original) { propertySetDict = ReflectionExtendHelper.PropertySetCallDict <T>(reflectionType); } T t = ReflectionGenericHelper.New <T>(); foreach (var keyValueItem in mapperDict) { if (propertySetDict != null && propertySetDict.ContainsKey(keyValueItem.Key.Name)) { ReflectionGenericHelper.SetPropertyValue(propertySetDict[keyValueItem.Key.Name], t, HttpUtility.UrlDecode(httpCookie[keyValueItem.Value]), keyValueItem.Key); } else { ReflectionHelper.SetPropertyValue(t, HttpUtility.UrlDecode(httpCookie[keyValueItem.Value]), keyValueItem.Key); } } return(t); }
internal static List <T> ExecuteToEntityList <T>(DataTable dataTable, Dictionary <string, object> propertyDict, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { Dictionary <PropertyInfo, string> columnNameDict = CommonHelper.InitPropertyReadMapper <T, DataTableTAttribute>(propertyDict, (name) => dataTable.Columns.Contains(name)); List <T> dataList = new List <T>(); dynamic propertySetDict = null; if (reflectionType != ReflectionTypeEnum.Original) { propertySetDict = ReflectionExtendHelper.PropertySetCallDict <T>(reflectionType); } // 读取 DataTable 数据到实体对象列表中 foreach (DataRow dataRow in dataTable.Rows) { dataList.Add(DataRowToEntity <T>(dataRow, propertySetDict, columnNameDict)); } return(dataList); }