Click here to Skip to main content
15,897,334 members
Articles / Programming Languages / C# 4.0

Intelligent Command Line Parser

Rate me:
Please Sign up or sign in to vote.
4.90/5 (27 votes)
29 May 2012CPOL4 min read 38.6K   1K   83  
Parses command line arguments and converts them into objects for use in your application
namespace CommandLineParser
{
    using System;

    /// <summary>
    /// Attribute to decorate the IArguments members
    /// </summary>
    public sealed class ArgumentAttribute : Attribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ArgumentAttribute"/> class.
        /// </summary>
        public ArgumentAttribute()
        {
            this.Required = false;
            this.DefaultValue = null;
        }

        /// <summary>
        /// Gets or sets the short name.
        /// </summary>
        /// <value>The short name.</value>
        /// <example>-f -s</example>
        public string ShortName { get; set; }

        /// <summary>
        /// Gets or sets the long name.
        /// </summary>
        /// <value>The long name.</value>
        /// <example>-file -save</example>
        public string LongName { get; set; }

        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        /// <value>The description.</value>
        public string Description { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="ArgumentAttribute"/> is required.
        /// </summary>
        /// <value><c>true</c> if required; otherwise, <c>false</c>.</value>
        public bool Required { get; set; }

        /// <summary>
        /// Gets or sets the default value.
        /// </summary>
        /// <value>The default value.</value>
        public object DefaultValue { get; set; }
    }
}

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)


Written By
Software Developer (Senior) Performance Web
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions