ParamGate application parameter handling library


This is my own attempt of writing a library that can aid a developer with application parameter handling.
Just to clear out any misunderstanding, the parameters I'm referring to are the parameters a user types in when executing a console or GUI type application.

ParamGate allows you to have your application do the following:

MyApp.exe Value1 Value2 -Flag1 -Name Danny -Item-Collection Item1 Item2

If you have a class that looks like this:

public class ParameterInfo
  [OptionalParameter(IsDefault = true)]
  public string[] Values { get; set; }

  public bool Flag1 { get; set; }

  public string Name { get; set; }

  [OptionalParameter(Name = "Item-Collection")]
  public ICollection<string> ItemsCollection { get; set; }

It will be populated like this:

ParameterInfo.Values will have the string array of { "Value1", "Value2" }
ParameterInfo.Flag1 will be TRUE
ParameterInfo.Name will be Danny
ParameterInfo.ItemsCollection will have the collection of { "Item1", "Item2" }

Note that properties without any of the ExpectedParameter or OptionalParameter attributes will automatically be recognized as optional.
You may even have other attributes which will be used to validate the parameter value(s) being parsed. For instance, a built-in attribute called FilesystemParameter can be used to verify if the parameter is a valid file/directory path and/or if that file/directory exists.
ParamGate offers you the possibility of writing your own attributes to be used like this which will be automatically executed when parsing parameters.

To use this library you need the RenewalProjects.Libraries.ParamGate.dll library.
Then you need to create a class that will represent your application parameters like the example above.
After that you need to pass your arguments and your parameter-class instance to the ParamGateHandler.

static void Main(string[] args)
  ParameterInfo param = new ParameterInfo();
    ParamGateHandler.ProcessArguments(args, param);
    // Now make use of your param instance in your application.
  catch(ParameterValidationException ex)
    // Handle parameter validation error
  catch(ParamGateException ex)
    // General error with ParamGate

Other topics

Last edited Mar 9, 2013 at 5:55 AM by dandrejvv, version 6


No comments yet.