public static string GetSectionName(this IProepertyEntity obj) { var name = ""; var type = obj.GetType(); var info = type.GetProperty("SectionName"); if (info != null) { var value = info.GetValue(obj, null); name = value == null ? "" : value.ToString(); } return(name.ToLower()); }
public static SectionData ToSectionData(this IProepertyEntity obj) { var sectionName = obj.GetSectionName(); if (string.IsNullOrEmpty(sectionName)) { return(null); } var sectionData = new SectionData(sectionName); var type = obj.GetType(); foreach (var item in type.GetProperties()) { if (item.GetCustomAttribute(typeof(ObsoleteAttribute)) != null || item.GetCustomAttribute(typeof(SectionNameAttribute)) != null) { continue; } var key = item.Name.ToLower(); var attr = (PropertyKeyAttribute)item.GetCustomAttribute(typeof(PropertyKeyAttribute)); if (attr != null) { key = attr.Name; } var value = item.GetValue(obj, null); if (value == null || string.IsNullOrWhiteSpace(value.ToString())) { continue; } if (item.PropertyType.Name == typeof(int).Name && value.Equals(0)) { continue; } if (item.PropertyType.IsEnum && value.ToString().Equals("None")) { continue; } sectionData.Keys.AddKey(key, value.ToString().ToLower()); } return(sectionData); }