private static IEnumerable <PropertyInfo> SortAndFilterProperties(Type type, bool isList) { if (type.Module.ScopeName == "CommonLanguageRuntimeLibrary") { return(null); } SortedDictionary <int, PropertyInfo> orderedProperties = new SortedDictionary <int, PropertyInfo>(); List <PropertyInfo> unorderedProperties = new List <PropertyInfo>(); foreach (PropertyInfo property in type.GetProperties()) { DisplayAttribute displayAttribute = property.GetCustomAttribute <DisplayAttribute>(); if (displayAttribute != null) { if (isList) { if (displayAttribute.GetListOrder().HasValue&& !displayAttribute.ListOmit) { orderedProperties.Add(displayAttribute.ListOrder, property); } else if (!displayAttribute.ListOmit) { unorderedProperties.Add(property); } } else { if (displayAttribute.GetOrder().HasValue&& !displayAttribute.Omit) { orderedProperties.Add(displayAttribute.Order, property); } else if (!displayAttribute.Omit) { unorderedProperties.Add(property); } } continue; } unorderedProperties.Add(property); } return(orderedProperties.Select(c => c.Value).Concat(unorderedProperties)); }