Skip to content

Commit 39d1703

Browse files
committed
Update Validate() to use CustomAttributes
With the `CustomAttributes` now exposed to the underlying `ItemConfiguration` as a protected property (9705824), the `PropertyConfiguration.Validate()` method can now access those instead of making a direct call to `GetCustomAttributes()`. This also updates the code to use the `MemberAccessor` version of `GetValue()` instead of going directly through reflection, which should have a slight performance benefit. Technically, this could have been done before when the dependency on `MemberAccessor` was introduced to `PropertyConfiguration` (49ffd61). As we hadn't updated `ItemConfiguration` to operate off of `CustomAttributes` yet, however, I waited to migrate this so they could operate off of the same base property (9705824).
1 parent ed688f9 commit 39d1703

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

OnTopic/Mapping/Internal/PropertyConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ internal PropertyConfiguration(MemberAccessor memberAccessor, string? attributeP
7575
/// </summary>
7676
/// <param name="target">The target DTO to validate the current property on.</param>
7777
internal void Validate(object target) {
78-
foreach (ValidationAttribute validator in Property.GetCustomAttributes(typeof(ValidationAttribute))) {
79-
validator.Validate(Property.GetValue(target), Property.Name);
78+
foreach (ValidationAttribute validator in CustomAttributes.OfType<ValidationAttribute>()) {
79+
validator.Validate(MemberAccessor.GetValue(target), MemberAccessor.Name);
8080
}
8181
}
8282

0 commit comments

Comments
 (0)