Documentation for the C# command-line option parsing library

PropertyFieldParserHelper Class

Helper class for the parser that stores values into properties and fields of a class.

For a list of all members of this type, see PropertyFieldParserHelper Members.


public class PropertyFieldParserHelper : IOptionResults, IOptionContainer


Used to create option definitions from properties and fields of an object. Options are defined using OptDefAttribute, UseNameAsLongOptionAttribute, LongOptionNameAttribute, ShortOptionNameAttribute, DefaultValueAttribute, CategoryAttribute, and DescriptionAttribute attributes.


Example class implementing options via attributes:

// Example class defining properties
class Properties
    #region Enumerations
    internal enum ExamplePropertyEnum
    #endregion Enumerations

    #region Members
    private ExamplePropertyEnum _exampleEnumProp;
    #endregion Members

    #region Accessed by code properties
    // Cannot be used by the parser easily, but can be used
    // by code
    public ExamplePropertyEnum ExampleEnumProp 
        get { return _exampleEnumProp; }
        set { _exampleEnumProp = value; }
    #endregion Accessed by code properties

    #region Options
    // Cannot be used by the parser easily, but can be used
    // by code
    // The EditorBrowsableAttribute is used to hide this 
    // property from code
    [Description("Show how to perform complex type option parsing")]
    public string ExampleEnumPropAsString
        get { return _exampleEnumProp.ToString(); }
            switch (value.ToLower())
                case "first": _exampleEnumProp = ExamplePropertyEnum.First; break;
                case "second": _exampleEnumProp = ExamplePropertyEnum.Second; break;
                    throw new ArgumentException(
                        "Invalid value for the example-enum-prop option");

    // Example of how to reverse flag-option values
    [Description("Disable debug output")]
    public bool NoDebug
        get { return !this.Debug; }
        set { this.Debug = !value; }

    [Description("Enable debug output")]
    public bool Debug = false;

    [Description("Output directory")]
    public string Directory = ".";

    [Description("Input file")]
    public string File = null;

    [Description("Set level of vebosity for debug printing")]
    public int Verbose = 0;

    [OptDef(OptValType.MultValue, ValueType=typeof(string))]
    [Description("Test option that takes multiple values")]
    public StringCollection Strings = new StringCollection();
    #endregion Options


Namespace: CommandLine.OptParse

Assembly: CSharpOptParse (in CSharpOptParse.dll)

See Also

PropertyFieldParserHelper Members | CommandLine.OptParse Namespace | Parser | ParserFactory | OptDefAttribute | UseNameAsLongOptionAttribute | LongOptionNameAttribute | ShortOptionNameAttribute | DefaultValueAttribute | CategoryAttribute | DescriptionAttribute