Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of ValidationResult.Success field?

Tags:

Msdn:

public static readonly ValidationResult ValidationResult.Success

Represents the success of the validation (true if validation was successful; otherwise, false).

The text in above excerpt doesn't make sense to me, since Success field doesn't return a value of type bool, and the value it does return ( ie ValidationResult instance ) doesn't contain any boolean property or field which we could set to a value indicating a success or failure of a validation?!

Any ideas what is the purpose of this field?

like image 711
carewithl Avatar asked Dec 03 '12 21:12

carewithl


People also ask

What is ValidationResult?

ValidationResult(String, IEnumerable<String>) Initializes a new instance of the ValidationResult class by using an error message and a list of members that have validation errors. ValidationResult(ValidationResult) Initializes a new instance of the ValidationResult class by using a ValidationResult object.

What is Validationcontext?

This class describes the type or member on which validation is performed. It also enables custom validation to be added through any service that implements the IServiceProvider interface.

What is Property validation attribute?

Validates that a property value matches a specified regular expression. Built-in. Remote. Performs a remote validation: you call an action method on the server to validate inputs on the client.


1 Answers

ValidationResult.Success is always constant null. Its purpose is documentation.

In order to succeed validation you could either write:

return null; 

or

return ValidationResult.Success; 

In the first case I ask myself "What does this mean? What does null mean? Is this success, or fail, or something else?". In the latter case the code is inherently documented without the need for informal text docs.

like image 94
usr Avatar answered Oct 03 '22 17:10

usr