ValidationContext.LogWarning Method
Creates a validation warning and logs the 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 LogWarning ( _
description As String, _
code As String, _
ParamArray elements As ModelElement() _
) As ValidationMessage
public ValidationMessage LogWarning(
string description,
string code,
params ModelElement[] elements
)
public:
ValidationMessage^ LogWarning(
String^ description,
String^ code,
... array<ModelElement^>^ elements
)
member LogWarning :
description:string *
code:string *
elements:ModelElement[] -> ValidationMessage
public function LogWarning(
description : String,
code : String,
... elements : ModelElement[]
) : ValidationMessage
Parameters
description
Type: System.StringThe text that describes this warning and that appears in the Error List window if a violation is found.
code
Type: System.StringA unique string that identifies this warning.
elements
Type: array<Microsoft.VisualStudio.Modeling.ModelElement[]A list of zero or more elements that are in the model and 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 has information about the warning.
Remarks
LogWarning does not send the validation warning to Visual Studio.
The VsValidationContext object causes the warning 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 name of each instance of the class in which it is defined exists and that the name matches the expected format for regular expressions.
If a violation is encountered, the LogWarning method adds a warning to the list to appear in the Error List window.
[C#]
[ValidationMethod(
ValidationCategory.Menu
| ValidationCategory.Open
| ValidationCategory.Save)
]
protected void ValidateNameCorrectForm(ValidationContext context)
{
if (this.Name == null || this.Name.Trim().Length == 0 ||
!System.Text.RegularExpressions.Regex.IsMatch(this.Name,
"^[A-Za-z][A-Za-z0-9_]*$"))
{
string desc =
String.Format(CultureInfo.CurrentCulture,
DomainModel_Resource.WizardPageNameForm,
this.Name);
context.LogWarning(desc, "WizardPageNameForm", 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.