/// <summary> /// Set the metadata of authentication. /// </summary> /// <param name="authentication"></param> protected virtual void SetAuthentication(EntityAuthenticationAttribute authentication) { if (authentication == null) { throw new ArgumentNullException("authentication"); } AllowAnonymous = authentication.AllowAnonymous; AddRoles = new ReadOnlyCollection <object>(authentication.AddRolesRequired); EditRoles = new ReadOnlyCollection <object>(authentication.EditRolesRequired); ViewRoles = new ReadOnlyCollection <object>(authentication.ViewRolesRequired); RemoveRoles = new ReadOnlyCollection <object>(authentication.RemoveRolesRequired); AuthenticationRequiredMode = authentication.Mode; }
/// <summary> /// Set the metadata automatic. /// </summary> protected virtual void SetMetadata() { DisplayNameAttribute display = Type.GetCustomAttribute <DisplayNameAttribute>(); if (display != null) { SetDisplay(display); } else { Name = Type.Name; } DisplayColumnAttribute displayColumn = Type.GetCustomAttribute <DisplayColumnAttribute>(); if (displayColumn != null) { SetDisplayColumn(displayColumn); } else { DisplayProperty = GetProperty("Index"); } ParentAttribute parent = Type.GetCustomAttribute <ParentAttribute>(); if (parent != null) { SetParent(parent); } EntityAuthenticationAttribute authenticate = Type.GetCustomAttribute <EntityAuthenticationAttribute>(); if (authenticate == null) { AllowAnonymous = true; AddRoles = new string[0]; EditRoles = new string[0]; ViewRoles = new string[0]; RemoveRoles = new string[0]; } else { SetAuthentication(authenticate); } }
/// <summary> /// Initialize entity metadata. /// </summary> /// <param name="type"></param> public EntityMetadata(Type type) { if (type == null) { throw new ArgumentNullException("type"); } Type = type; KeyType = type.GetProperty("Index").PropertyType; PropertyInfo[] properties = type.GetProperties().Where(t => t.GetGetMethod() != null && t.GetSetMethod() != null).ToArray(); Properties = properties.Select(t => new PropertyMetadata(t)).OrderBy(t => t.Order).ToArray(); ViewProperties = Properties.Where(t => !t.IsHiddenOnView).ToArray(); EditProperties = Properties.Where(t => !t.IsHiddenOnEdit).ToArray(); SearchProperties = Properties.Where(t => t.Searchable).ToArray(); DetailProperties = Properties.Where(t => !t.IsHiddenOnDetail).ToArray(); _Properties = new Dictionary <string, PropertyMetadata>(); for (int i = 0; i < Properties.Length; i++) { _Properties.Add(Properties[i].Property.Name, Properties[i]); } EntityAuthenticationAttribute authenticate = type.GetCustomAttribute <EntityAuthenticationAttribute>(); if (authenticate == null) { AllowAnonymous = true; AddRoles = new string[0]; EditRoles = new string[0]; ViewRoles = new string[0]; RemoveRoles = new string[0]; } else { AllowAnonymous = authenticate.AllowAnonymous; AddRoles = authenticate.AddRolesRequired; EditRoles = authenticate.EditRolesRequired; ViewRoles = authenticate.ViewRolesRequired; RemoveRoles = authenticate.RemoveRolesRequired; } DisplayNameAttribute display = type.GetCustomAttribute <DisplayNameAttribute>(); if (display != null) { Name = display.DisplayName == null ? type.Name : display.DisplayName; } else { Name = type.Name; } DisplayColumnAttribute displayColumn = type.GetCustomAttribute <DisplayColumnAttribute>(); if (displayColumn != null) { DisplayProperty = GetProperty(displayColumn.DisplayColumn); if (displayColumn.SortColumn != null) { SortProperty = Properties.SingleOrDefault(t => t.Property.Name == displayColumn.SortColumn); SortDescending = displayColumn.SortDescending; } } else { DisplayProperty = GetProperty("Index"); } ParentAttribute parent = type.GetCustomAttribute <ParentAttribute>(); if (parent != null) { ParentProperty = Properties.SingleOrDefault(t => t.Property.Name == parent.PropertyName); ParentLevel = parent.Level; } }