forked from haoduotnt/aspnetwebstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCachedDataAnnotationsMetadataAttributes.cs
More file actions
56 lines (41 loc) · 2.45 KB
/
CachedDataAnnotationsMetadataAttributes.cs
File metadata and controls
56 lines (41 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) Microsoft Open Technologies, Inc. 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<DataTypeAttribute>().FirstOrDefault();
Display = attributes.OfType<DisplayAttribute>().FirstOrDefault();
DisplayColumn = attributes.OfType<DisplayColumnAttribute>().FirstOrDefault();
DisplayFormat = attributes.OfType<DisplayFormatAttribute>().FirstOrDefault();
DisplayName = attributes.OfType<DisplayNameAttribute>().FirstOrDefault();
Editable = attributes.OfType<EditableAttribute>().FirstOrDefault();
HiddenInput = attributes.OfType<HiddenInputAttribute>().FirstOrDefault();
ReadOnly = attributes.OfType<ReadOnlyAttribute>().FirstOrDefault();
Required = attributes.OfType<RequiredAttribute>().FirstOrDefault();
ScaffoldColumn = attributes.OfType<ScaffoldColumnAttribute>().FirstOrDefault();
var uiHintAttributes = attributes.OfType<UIHintAttribute>();
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; }
}
}