ValidationMethodAttribute Class

 

Apply this attribute to methods that should be invoked during validation.

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

System::Object
  System::Attribute
    Microsoft.VisualStudio.Modeling.Validation::ValidationMethodAttribute

[AttributeUsageAttribute(AttributeTargets::Method, AllowMultiple = true)]
public ref class ValidationMethodAttribute sealed : Attribute

NameDescription
System_CAPS_pubmethodValidationMethodAttribute()

Apply this attribute to methods that you want to be called when the user invokes the Validate menu command.

System_CAPS_pubmethodValidationMethodAttribute(ValidationCategories)

Apply this attribute to methods that you want to be called during validation.

NameDescription
System_CAPS_pubpropertyCategories

Defines when the method to which this attribute is applied will be called.

System_CAPS_pubpropertyCustomCategory

Gets or sets the custom validation category, which can be empty.

System_CAPS_pubpropertyTypeId

(Inherited from Attribute.)

NameDescription
System_CAPS_pubmethodEquals(Object^)

(Inherited from Attribute.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Attribute.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodIsDefaultAttribute()

(Inherited from Attribute.)

System_CAPS_pubmethodMatch(Object^)

(Inherited from Attribute.)

System_CAPS_pubmethodToString()

(Inherited from Object.)

The Categories property determines when the attribute is used.

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

The following example decorates a method in the Person class to be invoked when validation occurs. The ValidationCategories enumeration setting indicates when the method will be invoked.

[C#]

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