Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Add more details to ModelAttributes #2395

Closed
wants to merge 2 commits into from
Closed

Add more details to ModelAttributes #2395

wants to merge 2 commits into from

Conversation

rynowak
Copy link
Member

@rynowak rynowak commented Apr 16, 2015

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

@ghost ghost added the cla-already-signed label Apr 16, 2015
@@ -29,7 +29,7 @@ public void GetBindingMetadata([NotNull] BindingMetadataProviderContext context)
}

var dataMemberAttribute = context
.Attributes
.PropertyAttributes
Copy link
Member Author

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).

@rynowak
Copy link
Member Author

rynowak commented Apr 16, 2015

/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)
Copy link
Member

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? 😺

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh.

@dougbu
Copy link
Member

dougbu commented Apr 17, 2015

@rynowak
Copy link
Member Author

rynowak commented Apr 17, 2015

@dougbu updated

@@ -36,6 +39,16 @@ public class BindingMetadataProviderContext
public ModelMetadataIdentity Key { get; }

/// <summary>
/// Gets the property attributes.
/// </summary>
public IReadOnlyList<object> PropertyAttributes { get; }
Copy link
Member

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;

Copy link
Member Author

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.

Copy link
Member Author

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.

rynowak added 2 commits April 17, 2015 13:13
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
@@ -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]));
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@dougbu
Copy link
Member

dougbu commented Apr 17, 2015

:shipit:

@rynowak rynowak closed this Apr 18, 2015
@rynowak rynowak deleted the model-attributes branch April 18, 2015 00:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants