Skip to content

Commit

Permalink
Give ValidationContext.MemberName a distinct value from DisplayName
Browse files Browse the repository at this point in the history
- #120

`ValidationAttribute` classes that (incorrectly) expected `MemberName` to always be set or that
instantiate `ValidationResult`s using the `DisplayName` may be negatively impacted. For exmaple,
`MemberName` will be `null` when binding parameters and items in a collection.
  • Loading branch information
dougbu committed Jan 23, 2018
1 parent a18ca4a commit 7b3e1e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public override IEnumerable<ModelValidationResult> Validate(ModelMetadata metada
// Per the WCF RIA Services team, instance can never be null (if you have
// no parent, you pass yourself for the "instance" parameter).

string memberName = metadata.GetDisplayName();
var memberName = metadata.PropertyName;
ValidationContext context = new ValidationContext(container ?? metadata.Model)
{
DisplayName = memberName,
MemberName = memberName
DisplayName = metadata.GetDisplayName(),
MemberName = memberName,
};

ValidationResult result = Attribute.GetValidationResult(metadata.Model, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static TheoryDataSet<ModelMetadata, string> ValidateSetsMemberNamePropert
},
{
_metadataProvider.GetMetadataForType(() => new object(), typeof(SampleModel)),
"SampleModel"
null
}
};
}
Expand Down

0 comments on commit 7b3e1e8

Please sign in to comment.