Delen via


ValidationContext.LogMessage Method

Creates a validation information message and logs it 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)

Syntax

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

Parameters

  • description
    Type: System.String

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

  • code
    Type: System.String

    A unique string that identifies this message.

Return Value

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

Remarks

LogMessage does not send the validation message to Visual Studio.

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

Note

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 validates whether the number of children for each Person is not larger than 20.

If a violation is encountered, the LogMessage method adds a warning to the list of messages that appear in the Error List window.

[C#]

[ValidationMethod
(
    ValidationCategory.Open |
    ValidationCategory.Save |
    ValidationCategory.Menu
)
]
private void ValidateNumberOfChildren(ValidationContext context)   
{
    if (this.Child.Count > 20)
    {
        context.LogMessage(
            "Number of children: " + this.Child.Count,
            "HighNumberOfChildren", 
            this 
        );
    }
}

.NET Framework Security

See Also

Reference

ValidationContext Class

Microsoft.VisualStudio.Modeling.Validation Namespace