internal static DataTable ExecuteToDataTable <T>(List <T> dataList, Dictionary <string, object> propertyDict, List <string> propertyList = null, bool propertyContain = true, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { Dictionary <string, string> columnNameList = CommonHelper.InitPropertyWriteMapper <T, DataTableTAttribute>(propertyDict, propertyList, propertyContain); DataTable dataTable = new DataTable(); // 遍历设置标题 foreach (KeyValuePair <string, string> keyValuePair in columnNameList) { dataTable.Columns.Add(keyValuePair.Key); } dynamic propertyGetDict = null; if (reflectionType != ReflectionTypeEnum.Original) { propertyGetDict = ReflectionExtendHelper.PropertyGetCallDict <T>(reflectionType); } DataRow dataRow = null; // 遍历数据并设置到 DataTable foreach (T t in dataList) { dataRow = dataTable.NewRow(); SetRowDataValue(dataRow, t, propertyGetDict, columnNameList); dataTable.Rows.Add(dataRow); } return(dataTable); }
internal static void ExecuteSetCookie <T>(HttpResponseBase httpResponse, string cookieName, T data, DateTime expires, Dictionary <string, object> propertyDict, List <string> propertyList, bool propertyContain = true, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { Dictionary <string, string> cookieNameDict = CommonHelper.InitPropertyWriteMapper <T, CookieTAttribute>(propertyDict, propertyList, propertyContain); dynamic propertyGetDict = null; if (reflectionType != ReflectionTypeEnum.Original) { propertyGetDict = ReflectionExtendHelper.PropertyGetCallDict <T>(reflectionType); } HttpCookie httpCookie = new HttpCookie(cookieName); httpCookie.HttpOnly = true; httpCookie.Expires = expires; object cookieValue = null; foreach (KeyValuePair <string, string> keyValueItem in cookieNameDict) { if (propertyGetDict != null && propertyGetDict.ContainsKey(keyValueItem.Value)) { cookieValue = propertyGetDict[keyValueItem.Value](data); } else { cookieValue = ReflectionHelper.GetPropertyValue(data, keyValueItem.Value); } if (cookieValue != null) { httpCookie.Values.Add(keyValueItem.Key, HttpUtility.UrlEncode(cookieValue.ToString())); } } if (httpResponse != null) { httpResponse.Cookies.Add(httpCookie); } else { HttpContext.Current.Response.Cookies.Add(httpCookie); } }