ParamGate application parameter handling library

Custom attributes

If you would like to create your own parameter validation attributes, create a class that derives from ParamGateAttributeBase.

public class MyValidatingPropertyAttribute : ParamGateAttributeBase
{
  public string SomeSetting { get; set; }
  
  public void ValidateAttribute()
  {
     // Validate that SomeSetting is correct. Throw ParamGateException if not valid.
  }

  public void ValidateParameter(string parameterName, object parameterValue)
  {
     // Validate the parameter value. The parameter name is given to help the end-user identify which parameter has the error.
     // Throw a ParameterValidationException if validation fails.
  }
}

Now you can add it to your parameter-class instance:

public class ParameterInfo
{
   [MyValidatingProperty(SomeSetting = "A")]
   public string PropertyInstance { get; set; }
}

Last edited Sep 2, 2011 at 6:32 PM by dandrejvv, version 1

Comments

No comments yet.