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.11.0 (in Microsoft.VisualStudio.Modeling.Sdk.11.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: StringThe text that describes this message and that appears in the Error List window if a violation is found.
code
Type: StringA unique string that identifies this message.
elements
Type: array<Microsoft.VisualStudio.Modeling.ModelElement[]A list of zero or more elements that are in the model and that are highlighted if 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 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
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.