// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; namespace System.Web.Mvc { public class CachedDataAnnotationsMetadataAttributes { public CachedDataAnnotationsMetadataAttributes(Attribute[] attributes) { DataType = attributes.OfType().FirstOrDefault(); Display = attributes.OfType().FirstOrDefault(); DisplayColumn = attributes.OfType().FirstOrDefault(); DisplayFormat = attributes.OfType().FirstOrDefault(); DisplayName = attributes.OfType().FirstOrDefault(); Editable = attributes.OfType().FirstOrDefault(); HiddenInput = attributes.OfType().FirstOrDefault(); ReadOnly = attributes.OfType().FirstOrDefault(); Required = attributes.OfType().FirstOrDefault(); ScaffoldColumn = attributes.OfType().FirstOrDefault(); var uiHintAttributes = attributes.OfType(); UIHint = uiHintAttributes.FirstOrDefault(a => String.Equals(a.PresentationLayer, "MVC", StringComparison.OrdinalIgnoreCase)) ?? uiHintAttributes.FirstOrDefault(a => String.IsNullOrEmpty(a.PresentationLayer)); if (DisplayFormat == null && DataType != null) { DisplayFormat = DataType.DisplayFormat; } } public DataTypeAttribute DataType { get; protected set; } public DisplayAttribute Display { get; protected set; } public DisplayColumnAttribute DisplayColumn { get; protected set; } public DisplayFormatAttribute DisplayFormat { get; protected set; } public DisplayNameAttribute DisplayName { get; protected set; } public EditableAttribute Editable { get; protected set; } public HiddenInputAttribute HiddenInput { get; protected set; } public ReadOnlyAttribute ReadOnly { get; protected set; } public RequiredAttribute Required { get; protected set; } public ScaffoldColumnAttribute ScaffoldColumn { get; protected set; } public UIHintAttribute UIHint { get; protected set; } } }