ValidationContext Class


Contains information about the current validation processing being performed.

Namespace:   Microsoft.VisualStudio.Modeling.Validation
Assembly:  Microsoft.VisualStudio.Modeling.Sdk.12.0 (in Microsoft.VisualStudio.Modeling.Sdk.12.0.dll)


public class ValidationContext


Gets the validation categories for this validation context.


Gets the collection of validation messages for the validation context.


Gets the custom validation strings for the validation context.


Gets the list of model elements to validate.

System_CAPS_protmethodConstructValidationMessage(String, String, ViolationType, ModelElement[])

Constructs a validation message. You can override this method to construct a custom validation message.


(Inherited from Object.)


(Inherited from Object.)


Gets the cache for the specified class.


Gets the cache for the specified class.


(Inherited from Object.)


Gets the proxy model elements when a validation error occurs in the model.


(Inherited from Object.)

System_CAPS_pubmethodLogError(String, String, ModelElement[])

Creates a validation error and logs a message into the collection that the validation context maintains.

System_CAPS_pubmethodLogFatal(String, String, ModelElement[])

Creates a fatal error for validation and logs a message in the validation context.

System_CAPS_pubmethodLogMessage(String, String, ModelElement[])

Creates a validation information message and logs it into the collection that the validation context maintains.

System_CAPS_pubmethodLogViolation(ViolationType, String, String, ModelElement[])

Creates a validation error, message, or warning.

System_CAPS_pubmethodLogWarning(String, String, ModelElement[])

Creates a validation warning and logs the message into the collection that the validation context maintains.


(Inherited from Object.)

System_CAPS_pubmethodSetCacheValue<T>(String, T)

Set the cached object associated with the name


(Inherited from Object.)

System_CAPS_pubmethodTryGetCacheValue<T>(String, T)

Returns whether the cached object associated with the name exist or not

An instance of this class is created every time that the modeling namespace starts the validation checking. This instance is passed into each validation method that you have registered for validation checking.

Each time that a validation method that you write is called, your code can log validation errors by using the LogError, LogWarning, and LogMessage methods. These validation errors are added to the CurrentViolations property of the ValidationContext object.

When the validation is finished, all validation errors, warnings, and messages are represented as collections of LogMessage objects in the CurrentViolations property.

The ValidationContext object is then passed to any subsequent validation methods. The CurrentViolations property contains all the errors, warnings, and messages that were encountered up to that point in the current validation checking.

The next time that validation starts, another ValidationContext object is created. That object is passed to each validation method in turn with errors, warnings, and messages added to that object as they are encountered.

For more information, see Validation in a Domain-Specific Language.

The following example is a method that is decorated by an attribute that indicates that it is a validation method.

The ValidationContext object that is passed into each validation method contains information about the current validation processing. This information includes the errors, warnings, and messages that accumulated in the validation methods that have already run.

The ValidationContext object has methods that add to the errors, warnings, and messages, such as the LogError method in the following example:

    ValidationCategory.Open |
    ValidationCategory.Save |
private void ValidateParentBirth(ValidationContext context)
    foreach (Person parent in this.Parent)
        if (this.Birth <= parent.Birth)
                       "Birth must be after Parent's birth",

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top