public string ToHtmlTableByProperties <T>(IEnumerable <T> enums) { var firstData = enums.FirstOrDefault(); //done: First use type with GetType func then type with typeof var type = firstData != null ? firstData.GetType() : typeof(T); var props = GetPropertiesByAttrSkipFiliter(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{_ThAttHtml}>{thInnerHTML}</th>"); } //Body var tbody = new StringBuilder(); foreach (var e in enums) { tbody.Append($"<tr{_TrAttHtml}>"); foreach (var prop in props) { var value = prop.GetToStringValue(e); string tdInnerHTML = Encode(value); tbody.Append($"<td{_TdAttHtml}>{tdInnerHTML}</td>"); } tbody.Append("</tr>"); } //Table html var html = RenderHtmlTable(thead, tbody); return(html.ToString()); }
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()); }