Help me understand the Validator.TryValidateObject () method

this is the definition of the method:

public static bool TryValidateObject(
Object instance,
ValidationContext validationContext,
ICollection<ValidationResult> validationResults,
bool validateAllProperties

)

that I am confused is a parameter validateAllProperties, I understand when it is true - check all the properties.

How about when it is false and does not check all the properties, but which property will be checked?

+3
source share
4 answers

, Validator , ValidationAttribute. : CustomValidationAttribute, DataTypeAttribute, RangeAttribute, RegularExpressionAttribute, RequiredAttribute StringLengthAttribute, , ValidationAttribute.

. MSDN TryValidateObject.

Foo , Bar .

public class Example
{
  [Required(ErrorMessage = "Foo is a required property.")]
  public object Foo { get; set; }

  public object Bar { get; set; }
}
+5

, Unit Testing, , .

( ), ! true, , TDD. , .

0

, Required , validateAllProperties .

OData DataAnnotations, .

http://blog.jorgef.net/2011/01/odata-dataannotations.html

0

Source: https://habr.com/ru/post/1748310/


All Articles