ValidationCategories Enumeration

 

This enumeration is a parameter for the constructor of the custom attribute, ValidationMethodAttribute. It specifies the type of validation in which the rule will be invoked.

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

[FlagsAttribute]
public enum class ValidationCategories

Member nameDescription
Custom

The method is for custom validation. To run this method, you can call ValidationController.ValidateCustom().

Load

Use this category for rules that check for conditions that will keep the model from loading. The method is invoked before a domain-specific language model is saved, to give the user a chance to correct any problems.

Menu

The method is invoked when the user selects ValidateAll on the shortcut menu.

Open

The validation method is invoked when the model is opened.

Save

Indicates that the validation method is invoked before a user of the domain-specific language saves the model.

This is a bitwise enumeration. The flags are not mutually exclusive.

The following example shows the ValidationCategory of a method in the Person class that is invoked when the user of a domain-specific language opens a model, saves a model, or clicks the validation command on the shortcut menu.

[C#]

[ValidationMethod
(
    ValidationCategories.Open |
    ValidationCategories.Save |
    ValidationCategories.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);
        }
    }
}
Return to top
Show: