Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Param.NET - An Automated Command-line Parameter Parser

, 19 Oct 2005 CPOL
A library that allows developers to specify the parameters that they expect to receive from the command line and provides an easier way to access them
using System;
using System.Configuration;
using System.Collections;
using System.Xml;

namespace Params
{
	public class ParamConfigurationSectionHandler : IConfigurationSectionHandler
	{
		#region IConfigurationSectionHandler Members

		public object Create(object parent, object context, System.Xml.XmlNode section)
		{
			if(ParamCollection.ApplicationParameters != null)
				throw(new Exception("ParamCollection already initialized. Use ParamCollection.ApplicationParameters."));

			ParamCollection col = new ParamCollection();

			col.DefaultAllowMultipleValues = Helper.GetBool(section.Attributes, "defaultAllowMultiple", false);
			col.DefaultIsOptional = Helper.GetBool(section.Attributes, "defaultOptional", false);
			col.DefaultType = (ParamType)Helper.GetEnum(section.Attributes, "defaultType", ParamType.String, typeof(ParamType));

			col.ShortControlString = Helper.GetString(section.Attributes, "shortControlString", "-");
			col.LongControlString = Helper.GetString(section.Attributes, "longControlString", "-");
			col.SeparatorChar = Helper.GetString(section.Attributes, "separatorChar", " ")[0];
			col.AttribChars = Helper.GetString(section.Attributes, "attribChars", " ").ToCharArray();
			col.AutoGenerateParams = Helper.GetBool(section.Attributes, "autoGenerateParams", false);

			foreach(XmlNode param in section.ChildNodes)
			{
				if(param.NodeType == XmlNodeType.Element && param.Name.ToLower() == "param")
				{
					col.Add(new Param(param, col));
				}
			}

			return col;
		}

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

eugen.anghel
Web Developer
Romania Romania
Just you average programmer geek from Romania. Student at Faculty of Computer Science, Al. I. Cuza University Iasi, Romania.

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 20 Oct 2005
Article Copyright 2005 by eugen.anghel
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid