StringValidatorAttribute Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Declaratively instructs .NET to perform string validation on a configuration property. This class cannot be inherited.
public ref class StringValidatorAttribute sealed : System::Configuration::ConfigurationValidatorAttribute
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class StringValidatorAttribute : System.Configuration.ConfigurationValidatorAttribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
type StringValidatorAttribute = class
inherit ConfigurationValidatorAttribute
Public NotInheritable Class StringValidatorAttribute
Inherits ConfigurationValidatorAttribute
- Inheritance
- Attributes
Examples
The following example shows how to decorate the properties of a custom ConfigurationSection object using the StringValidatorAttribute object.
[ConfigurationProperty("fileName", DefaultValue = "default.txt",
IsRequired = true, IsKey = false)]
[StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\",
MinLength = 1, MaxLength = 60)]
public string FileName
{
get
{
return (string)this["fileName"];
}
set
{
this["fileName"] = value;
}
}
<ConfigurationProperty("fileName", _
DefaultValue:="default.txt", _
IsRequired:=True, _
IsKey:=False), _
StringValidator( _
InvalidCharacters:=" ~!@#$%^&*()[]{}/;'""|\", _
MinLength:=1, _
MaxLength:=60)> _
Public Property FileName() As String
Get
Return CStr(Me("fileName"))
End Get
Set(ByVal value As String)
Me("fileName") = value
End Set
End Property
Remarks
You use the StringValidatorAttribute to decorate a configuration property. This is to instruct .NET to validate the property using the StringValidator and pass to it the value of the decorating parameters.
You can apply StringValidatorAttribute objects to property types only.
Constructors
| Name | Description |
|---|---|
| StringValidatorAttribute() |
Initializes a new instance of the StringValidatorAttribute class. |
Properties
| Name | Description |
|---|---|
| InvalidCharacters |
Gets or sets the invalid characters for the property. |
| MaxLength |
Gets or sets the maximum length allowed for the string to assign to the property. |
| MinLength |
Gets or sets the minimum allowed value for the string to assign to the property. |
| ValidatorInstance |
Gets an instance of the StringValidator class. |
| ValidatorType |
Gets the type of the validator attribute. (Inherited from ConfigurationValidatorAttribute) |