public IEnumerable <FieldConfig> GetFields(Type subject, Features features) { var properties = subject.GetProperties(); return(properties .Select(property => { var fieldAttribute = property.GetCustomAttribute <FieldAttribute>(); if (fieldAttribute != null) { var useListName = !features.HasFlag(Features.CanEdit) || features.HasFlag(Features.CanGoToEdit); var useName = features.HasFlag(Features.CanEdit) && !useListName; if ((useName && !string.IsNullOrEmpty(fieldAttribute.Name)) || (useListName && !string.IsNullOrEmpty(fieldAttribute.ListName))) { return (property, fieldAttribute); } } return default; }) .Where(x => x != default) .Select((data, index) => { if (data.fieldAttribute.EditorType?.IsSameTypeOrDerivedFrom(typeof(ComponentBase)) == false) { throw new InvalidOperationException("ResourceType of [Display] must be a valid BaseEditor derived component."); } var propertyMetadata = PropertyMetadataHelper.GetPropertyMetadata(subject, data.property); var propertyType = data.property.PropertyType.IsGenericType && data.property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>) ? Nullable.GetUnderlyingType(data.property.PropertyType) ! : data.property.PropertyType; var displayType = features.HasFlag(Features.CanEdit) ? DisplayType.None : DisplayType.Label; var editorType = !features.HasFlag(Features.CanEdit) ? EditorType.None : data.fieldAttribute.EditorType != null ? EditorType.Custom : EditorTypeHelper.TryFindDefaultEditorType(propertyType); var customType = editorType == EditorType.Custom ? data.fieldAttribute.EditorType : null; var relationConfig = editorType != EditorType.Select ? null : new DataProviderRelationConfig(typeof(EnumDataProvider <>).MakeGenericType(propertyType), default); return new FieldConfig { Description = features.HasFlag(Features.CanEdit) ? data.fieldAttribute.Description : default,
public IEnumerable <FieldConfig> GetFields(Type subject, Features features) { var properties = subject.GetProperties(); return(properties .Select(property => { var displayAttribute = property.GetCustomAttribute <DisplayAttribute>(); if (displayAttribute != null) { if ((features.HasFlag(Features.CanEdit) && !string.IsNullOrEmpty(displayAttribute.Name)) || (!features.HasFlag(Features.CanEdit) && !string.IsNullOrEmpty(displayAttribute.ShortName))) { return (property, displayAttribute); } } return default; }) .Where(x => x != default) .Select((data, index) => { if (data.displayAttribute.ResourceType?.IsSameTypeOrDerivedFrom(typeof(ComponentBase)) == false) { throw new InvalidOperationException("ResourceType of [Display] must be a valid BaseEditor derived component."); } var propertyMetadata = PropertyMetadataHelper.GetPropertyMetadata(subject, data.property); var displayType = features.HasFlag(Features.CanEdit) ? DisplayType.None : DisplayType.Label; var editorType = !features.HasFlag(Features.CanEdit) ? EditorType.None : data.displayAttribute.ResourceType != null ? EditorType.Custom : EditorTypeHelper.TryFindDefaultEditorType(data.property.PropertyType); var customType = editorType == EditorType.Custom ? data.displayAttribute.ResourceType : null; return new FieldConfig { Description = features.HasFlag(Features.CanEdit) ? data.displayAttribute.Description : default,