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.12.0 (in Microsoft.VisualStudio.Modeling.Sdk.12.0.dll)
Syntax
'Declaration
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.StringThe text that describes this error and that appear in the Error List window if a violation is found.
code
Type: System.StringA 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.
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.
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 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
- 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.