private IList <System.Reflection.PropertyInfo> GetGetPropertiesByAttrSkipFiliter(Type type) { var props = TypePropertiesCacheHelper.GetTypePropertiesCache(type); _customAttributes = CustomAttributeHelper.GetCustomAttributes(type); if (_customAttributes.FirstOrDefault() != null) { _customAttributes = _customAttributes.Where(attr => attr.Skip == false); var notSkipAttrsName = _customAttributes.Select(attr => attr.memberInfo.Name); props = props.Where(prop => notSkipAttrsName.Contains(prop.Name)).ToArray(); } return(props); }
public static IEnumerable <TableColumnAttribute> GetCustomAttributes(System.Type type) { var props = TypePropertiesCacheHelper.GetTypePropertiesCache(type); foreach (var prop in props) { var data = GetCustomAttribute(prop); if (data != null) { data.memberInfo = prop; } yield return(data); } }
private static Dictionary <string, string> AttributeToHtml <T>(T tableAttributes) { if (tableAttributes == null) { return(null); } var type = tableAttributes.GetType(); var dic = TypePropertiesCacheHelper.GetTypePropertiesCache(type) //.Select(prop => new { Key = prop.Name, Value = TypePropertiesCacheHelper.GetValueFromExpressionCache(type, prop, tableAttributes).ToString() }) #if !NET40 .Select(prop => new { Key = prop.Name, Value = prop.GetValue(tableAttributes).ToString() }) #endif #if NET40 .Select(prop => new { Key = prop.Name, Value = prop.GetValue(tableAttributes, null).ToString() }) #endif .ToDictionary(key => key.Key, value => value.Value); return(dic); }
public string ToHtmlTableByProperties <T>(IEnumerable <T> enums) { var type = typeof(T); var props = GetGetPropertiesByAttrSkipFiliter(type); #region Check if (props.Count == 0) { throw new Exception("At least one Property"); } #endregion //Head var thead = new StringBuilder(); foreach (var p in props) { var costomAtt = CustomAttributeHelper.GetCustomAttributeByProperty(_customAttributes, p); string thInnerHTML = costomAtt != null ? costomAtt.DisplayName : Encode(p.Name); thead.Append($"<th>{thInnerHTML}</th>"); } //Body var tbody = new StringBuilder(); foreach (var e in enums) { tbody.Append($"<tr{_TrAttHtml}>"); foreach (var prop in props) { var value = TypePropertiesCacheHelper.GetValueFromExpressionCache(type, prop, e); string tdInnerHTML = Encode(value); tbody.Append($"<td{_TdAttHtml}>{tdInnerHTML}</td>"); } tbody.Append("</tr>"); } //Table html var html = RenderHtmlTable(thead, tbody); return(html.ToString()); }