From d86298ffe1bd4acc0ac86fc4a4b8ba10c14b4a41 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 13 Mar 2014 15:44:12 -0700 Subject: [PATCH] Switching over placeholder attributes to use DataAnnotation attributes --- ...CachedDataAnnotationsMetadataAttributes.cs | 8 +----- .../CachedDataAnnotationsModelMetadata.cs | 26 ++----------------- .../Metadata/DisplayAttribute.cs | 20 -------------- .../Metadata/DisplayFormatAttribute.cs | 12 --------- .../Metadata/DisplayNameAttribute.cs | 9 ------- .../Metadata/EditableAttribute.cs | 12 --------- .../Metadata/ReadOnlyAttribute.cs | 10 ------- 7 files changed, 3 insertions(+), 94 deletions(-) delete mode 100644 src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/DisplayAttribute.cs delete mode 100644 src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/DisplayFormatAttribute.cs delete mode 100644 src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/DisplayNameAttribute.cs delete mode 100644 src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/EditableAttribute.cs delete mode 100644 src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/ReadOnlyAttribute.cs diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/CachedDataAnnotationsMetadataAttributes.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/CachedDataAnnotationsMetadataAttributes.cs index 11835bad16..2248065f84 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/CachedDataAnnotationsMetadataAttributes.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/CachedDataAnnotationsMetadataAttributes.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using System.Linq; namespace Microsoft.AspNet.Mvc.ModelBinding @@ -10,20 +10,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding public CachedDataAnnotationsMetadataAttributes(IEnumerable attributes) { Display = attributes.OfType().FirstOrDefault(); - DisplayName = attributes.OfType().FirstOrDefault(); DisplayFormat = attributes.OfType().FirstOrDefault(); Editable = attributes.OfType().FirstOrDefault(); - ReadOnly = attributes.OfType().FirstOrDefault(); } public DisplayAttribute Display { get; protected set; } - public DisplayNameAttribute DisplayName { get; protected set; } - public DisplayFormatAttribute DisplayFormat { get; protected set; } public EditableAttribute Editable { get; protected set; } - - public ReadOnlyAttribute ReadOnly { get; protected set; } } } diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/CachedDataAnnotationsModelMetadata.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/CachedDataAnnotationsModelMetadata.cs index 75fbe318b8..5c650e4d87 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/CachedDataAnnotationsModelMetadata.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/CachedDataAnnotationsModelMetadata.cs @@ -45,44 +45,22 @@ namespace Microsoft.AspNet.Mvc.ModelBinding return !PrototypeCache.Editable.AllowEdit; } - if (PrototypeCache.ReadOnly != null) - { - return PrototypeCache.ReadOnly.IsReadOnly; - } - return base.ComputeIsReadOnly(); } public override string GetDisplayName() { - // DisplayName could be provided by either the DisplayAttribute, or DisplayNameAttribute. If neither of - // those supply a name, then we fall back to the property name (in base.GetDisplayName()). - // - // DisplayName has lower precedence than Display.Name, for consistency with MVC. - // DisplayAttribute doesn't require you to set a name, so this could be null. if (PrototypeCache.Display != null) { - string name = PrototypeCache.Display.GetName(); + var name = PrototypeCache.Display.GetName(); if (name != null) { return name; } } - // It's also possible for DisplayNameAttribute to be used without setting a name. If a user does that, then DisplayName will - // return the empty string - but for consistency with MVC we allow it. We do fallback to the property name in the (unlikely) - // scenario that the user sets null as the DisplayName, again, for consistency with MVC. - if (PrototypeCache.DisplayName != null) - { - string name = PrototypeCache.DisplayName.DisplayName; - if (name != null) - { - return name; - } - } - - // If neither attribute specifies a name, we'll fall back to the property name. + // If DisplayAttribute does not specify a name, we'll fall back to the property name. return base.GetDisplayName(); } } diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/DisplayAttribute.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/DisplayAttribute.cs deleted file mode 100644 index d446d074e1..0000000000 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/DisplayAttribute.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Microsoft.AspNet.Mvc.ModelBinding -{ - public class DisplayAttribute : Attribute - { - internal string GetDescription() - { - throw new NotImplementedException(); - } - - internal string GetName() - { - throw new NotImplementedException(); - } - } -} diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/DisplayFormatAttribute.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/DisplayFormatAttribute.cs deleted file mode 100644 index a064ae7134..0000000000 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/DisplayFormatAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Microsoft.AspNet.Mvc.ModelBinding -{ - public class DisplayFormatAttribute : Attribute - { - public bool ConvertEmptyStringToNull { get; set; } - } -} diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/DisplayNameAttribute.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/DisplayNameAttribute.cs deleted file mode 100644 index 649424b891..0000000000 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/DisplayNameAttribute.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace Microsoft.AspNet.Mvc.ModelBinding -{ - public class DisplayNameAttribute : Attribute - { - public virtual string DisplayName { get; set; } - } -} diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/EditableAttribute.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/EditableAttribute.cs deleted file mode 100644 index ccc5dd5465..0000000000 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/EditableAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Microsoft.AspNet.Mvc.ModelBinding -{ - public class EditableAttribute : Attribute - { - public bool AllowEdit { get; set; } - } -} diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/ReadOnlyAttribute.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/ReadOnlyAttribute.cs deleted file mode 100644 index b4c4817823..0000000000 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/ReadOnlyAttribute.cs +++ /dev/null @@ -1,10 +0,0 @@ -#if K10 - -namespace Microsoft.AspNet.Mvc.ModelBinding -{ - public class ReadOnlyAttribute - { - public bool IsReadOnly { get; set; } - } -} -#endif \ No newline at end of file