G
Giuseppe Esposito
I don't know if it's the right name: I try to explain what I want to do.
Follow me. Wb.config file permits user to create personalized section.
The section can be read throught your ConfigurationSection's derived class
and each
element of the section should belong to a ConfigurationElement's derived
class.
Well. For standard field that return string, integer and so on, for each
attribute
you can use XXXXValidator to check if passed value is in a certain range.
That's fine, but I want to implement my own XXXX Validator.
So what I did is the following.
public sealed class ContentTypeValidator : ConfigurationValidatorBase
{
public override void Validate(object value)
{
ArrayList ct = new ArrayList();
ct.Add("text/plain");
ct.Add("text/HTML");
ct.Add("image/GIF");
ct.Add("image/JPEG");
ct.Add("image/TIFF");
ct.Add("application/pdf");
ct.Add("application/zip");
ct.Add("application/x-excel");
ct.Add("application/rtf");
try
{
if (Array.IndexOf(ct, value) == -1)
throw new ConfigurationErrorsException("Value isn't allowed");
}
catch (ConfigurationErrorsException err)
{
throw err;
}
}
}
I don't know if this is the right way to do what I want, but despite the
class doesn't contain
any formal error, if I got closest to my attribute declaration and press
[ and look for my Validator
class, it isn't there. What's the matter?
Thanks to all
Giusepp
Follow me. Wb.config file permits user to create personalized section.
The section can be read throught your ConfigurationSection's derived class
and each
element of the section should belong to a ConfigurationElement's derived
class.
Well. For standard field that return string, integer and so on, for each
attribute
you can use XXXXValidator to check if passed value is in a certain range.
That's fine, but I want to implement my own XXXX Validator.
So what I did is the following.
public sealed class ContentTypeValidator : ConfigurationValidatorBase
{
public override void Validate(object value)
{
ArrayList ct = new ArrayList();
ct.Add("text/plain");
ct.Add("text/HTML");
ct.Add("image/GIF");
ct.Add("image/JPEG");
ct.Add("image/TIFF");
ct.Add("application/pdf");
ct.Add("application/zip");
ct.Add("application/x-excel");
ct.Add("application/rtf");
try
{
if (Array.IndexOf(ct, value) == -1)
throw new ConfigurationErrorsException("Value isn't allowed");
}
catch (ConfigurationErrorsException err)
{
throw err;
}
}
}
I don't know if this is the right way to do what I want, but despite the
class doesn't contain
any formal error, if I got closest to my attribute declaration and press
[ and look for my Validator
class, it isn't there. What's the matter?
Thanks to all
Giusepp