Share via


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.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

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

Syntax

'Declaration
<FlagsAttribute> _
Public Enumeration ValidationCategories
[FlagsAttribute]
public enum ValidationCategories
[FlagsAttribute]
public enum class ValidationCategories
[<FlagsAttribute>]
type ValidationCategories
public enum ValidationCategories

Members

Member name Description
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.
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.

If a Load rule fails when the model is loaded, the model file will be opened with the XML editor rather than the DSL Designer.

Remarks

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

Examples

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

See Also

Reference

Microsoft.VisualStudio.Modeling.Validation Namespace

Other Resources

Validation in a Domain-Specific Language