Skip to content

Commit

Permalink
Merge pull request #103 from mimtari/OptimizeSetValidateAttribute
Browse files Browse the repository at this point in the history
Improve SetValidateAttribute performance
  • Loading branch information
runceel committed Apr 2, 2019
2 parents 2bdc0b1 + 350f1a6 commit 74a3450
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Linq.Expressions;
Expand Down Expand Up @@ -32,15 +33,13 @@ public static ReactiveProperty<T> SetValidateAttribute<T>(this ReactiveProperty<
{
self.SetValidateNotifyError(x =>
{
try
var validationResults = new List<ValidationResult>();
if (Validator.TryValidateValue(x, context, validationResults, attrs))
{
Validator.ValidateValue(x, context, attrs);
return null;
}
catch (ValidationException ex)
{
return ex.ValidationResult.ErrorMessage;
}
return validationResults[0].ErrorMessage;
});
}

Expand Down

0 comments on commit 74a3450

Please sign in to comment.