/// <summary> /// Returns a list of Role Permissions and their respective labels. If no (DisplayName) attribute present, will NOT be added to list. /// </summary> /// <param name="rp"></param> /// <returns></returns> public static Dictionary<string, bool> GetRolePermissionsList(RolePermissions rp) { var kvp = new Dictionary<string, bool>(); if (rp == null) { return kvp; } foreach (var prop in rp.GetType().GetProperties()) { // User Reflection to get custom atttributes Attribute[] attrs = System.Attribute.GetCustomAttributes(prop); var attr = attrs.FirstOrDefault(); string DisplayName; if (attr is DisplayAttribute) { var dispAttr = (DisplayAttribute)attr; DisplayName = dispAttr.Name; bool value = (bool)prop.GetValue(rp, null); kvp.Add(DisplayName, value); } } return kvp; }