-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Conversation
@@ -29,7 +29,7 @@ public void GetBindingMetadata([NotNull] BindingMetadataProviderContext context) | |||
} | |||
|
|||
var dataMemberAttribute = context | |||
.Attributes | |||
.PropertyAttributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is slightly more correct than what we were doing here before (which relies on the fact that [DataMember]
can't be put on a type).
/cc @dougbu |
@@ -19,7 +19,7 @@ public class DefaultMetadataDetails | |||
/// </summary> | |||
/// <param name="key">The <see cref="ModelMetadataIdentity"/>.</param> | |||
/// <param name="attributes">The set of model attributes.</param> | |||
public DefaultMetadataDetails(ModelMetadataIdentity key, IReadOnlyList<object> attributes) | |||
public DefaultMetadataDetails([NotNull] ModelMetadataIdentity key, [NotNull] ModelAttributes attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so a struct
can be null
now? 😺
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh.
⌚ |
@dougbu updated |
@@ -36,6 +39,16 @@ public class BindingMetadataProviderContext | |||
public ModelMetadataIdentity Key { get; } | |||
|
|||
/// <summary> | |||
/// Gets the property attributes. | |||
/// </summary> | |||
public IReadOnlyList<object> PropertyAttributes { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory could avoid "extra storage" and stop copying the ref in the ctor and implement this as something like:
public IReadOnlyList<object> PropertyAttributes { get; } => Attributes.PropertyAttributes;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would award a lot of #PranavPoints! I can't believe I didn't think of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is on a class that's created and then immediately thrown away so I'm not concerned about the extra two fields. Let me know if you think this is important.
This change adds more information to ModelAttributes, so that metadata providers can look at the attributes on the property and type separately if so desired
1ec3b51
to
dbbd457
Compare
@@ -551,7 +551,7 @@ public void GetValidationMetadata_RequiredAttribute_SetsIsRequiredToTrue() | |||
|
|||
var attributes = new Attribute[] { required }; | |||
var key = ModelMetadataIdentity.ForProperty(typeof(int), "Length", typeof(string)); | |||
var context = new ValidationMetadataProviderContext(key, attributes); | |||
var context = new ValidationMetadataProviderContext(key, new ModelAttributes(attributes, new object[0])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks new and different. am I correct calls to the 2-parameter ModelAttributes
constructor are all for property metadata?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Where the test is doing something with property metadata, I'm using the constructor that would be called by GetAttributesForProperty
. It's a bit of a formality and really not needed but I already took the time to make it consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
This change adds more information to ModelAttributes, so that metadata
providers can look at the attributes on the property and type separately
if so desired