ValidationContext.LogError Method

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.10.0 (in Microsoft.VisualStudio.Modeling.Sdk.10.0.dll)

Syntax

'Declaração
Public Function LogError ( _
    description As String, _
    code As String, _
    ParamArray elements As ModelElement() _
) As ValidationMessage
public ValidationMessage LogError(
    string description,
    string code,
    params ModelElement[] elements
)
public:
ValidationMessage^ LogError(
    String^ description, 
    String^ code, 
    ... array<ModelElement^>^ elements
)
member LogError : 
        description:string * 
        code:string * 
        elements:ModelElement[] -> ValidationMessage 
public function LogError(
    description : String, 
    code : String, 
    ... elements : ModelElement[]
) : ValidationMessage

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.

Return Value

Type: Microsoft.VisualStudio.Modeling.Validation.ValidationMessage
A validation message that contains information about the error.

Remarks

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.

Observação

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.

Examples

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

.NET Framework Security

See Also

Reference

ValidationContext Class

Microsoft.VisualStudio.Modeling.Validation Namespace