ValidationContext Class
Contains information about the current validation processing being performed.
Namespace: Microsoft.VisualStudio.Modeling.Validation
Assembly: Microsoft.VisualStudio.Modeling.Sdk (in Microsoft.VisualStudio.Modeling.Sdk.dll)
Syntax
'Declaration
Public Class ValidationContext
'Usage
Dim instance As ValidationContext
public class ValidationContext
public ref class ValidationContext
public class ValidationContext
Remarks
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 about validation, see How to: Add Validation to a Domain Language.
Examples
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:
[ValidationMethod
(
ValidationCategory.Open |
ValidationCategory.Save |
ValidationCategory.Menu
)
]
private void ValidateParentBirth(ValidationContext context)
{
foreach (Person parent in this.Parent)
{
if (this.Birth <= parent.Birth)
{
context.LogError(
"Birth must be after Parent's birth",
"FamilyParentBirthError",
this,
parent);
}
}
}
Inheritance Hierarchy
System.Object
Microsoft.VisualStudio.Modeling.Validation.ValidationContext
Microsoft.VisualStudio.Modeling.Shell.VsValidationContext
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.