ValidationContext::LogError Method (String^, String^, array<ModelElement^>^)

 

Creates a validation error and logs a message into the collection that the validation context maintains.

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

public:
ValidationMessage^ LogError(
	String^ description,
	String^ code,
	... array<ModelElement^>^ elements
)

Parameters

description
Type: System::String^

The text that describes this error and that appear in the Error List window if a violation is found.

code
Type: System::String^

A unique string that identifies this error.

elements
Type: array<Microsoft.VisualStudio.Modeling::ModelElement^>^

A list of zero or more elements in the model that are highlighted when a user double-clicks this message in the Error List window.

Return Value

Type: Microsoft.VisualStudio.Modeling.Validation::ValidationMessage^

A validation message that contains information about the error.

LogError does not send the validation error to Visual Studio.

The VsValidationContext object causes the error to appear in the Error List window of Visual Studio. The description that you provide as a parameter to this method is the textual explanation that appears in the window.

System_CAPS_noteNote

The elements in the list are also highlighted if the user right-clicks in the Error List window and then clicks Previous Error or Next Error.

The following example verifies whether the Birth property value of each Person is not before or equal to the Birth property value of its parents.

If a violation is encountered, the LogError method adds an error to the list of errors that appear in the Error List window.

[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);
        }
    }
}
Return to top
Show: