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)

System.Object
  Microsoft.VisualStudio.Modeling.Validation.ValidationContext
    Microsoft.VisualStudio.Modeling.Shell.VsValidationContext

public class ValidationContext

NameDescription
System_CAPS_pubpropertyCategories

Gets the validation categories for this validation context.

System_CAPS_pubpropertyCurrentViolations

Gets the collection of validation messages for the validation context.

System_CAPS_pubpropertyCustomCategories

Gets the custom validation strings for the validation context.

System_CAPS_pubpropertyValidationSubjects

Gets the list of model elements to validate.

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

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

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetCache<T>()

Gets the cache for the specified class.

System_CAPS_pubmethodGetCache<T>(String)

Gets the cache for the specified class.

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetNavigationProxyModelElements(ModelElement)

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

System_CAPS_pubmethodGetType()

(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.

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodSetCacheValue<T>(String, T)

Set the cached object associated with the name

System_CAPS_pubmethodToString()

(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:

[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);
        }
      }
}

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
Show: