Attributes.cs :  » Development » Command-Line-Option-Parsing » CommandLine » OptParse » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » Command Line Option Parsing 
Command Line Option Parsing » CommandLine » OptParse » Attributes.cs
/* This file is part of the CSharpOptParse .NET C# library
 *
 * The library is hosted at http://csharpoptparse.sf.net
 *
 * Copyright (C) 2005 by Andrew Robinson
 *
 * This source code is open source, protected under the GNU GPL Version 2, June 1991
 * Please see http://opensource.org/licenses/gpl-license.php for information and
 * specifics on this license.
 */
using System;
using System.ComponentModel;

namespace CommandLine.OptParse{
  #region OptDefAttribute
  /// <summary>
  /// Define that a property or field can be given as an option
  /// <seealso cref="Parser"/>
  /// </summary>
  /// <remarks>
  /// For <see cref="OptValType.Flag"/> the property or field must have be type of bool 
  /// <para>
  /// For <see cref="OptValType.IncrementalFlag"/> the property or field must be a integer
  /// </para>
  /// <para>
  /// For <see cref="OptValType.ValueReq"/> or <see cref="OptValType.ValueOpt"/> the
  /// property or field must be the type of the <see cref="ValueType"/> property.
  /// </para>
  /// <para>
  /// For <see cref="OptValType.MultValue"/> the property or field must be 
  /// an <see cref="System.Collections.IList"/> of values of the type defined by the
  /// <see cref="ValueType"/> property (IList cannot be null).
  /// </para>
  /// </remarks>
  /// <include file="ExternalDocs.xml" 
  ///    path="externalDocs/doc[@name='ExamplePropClass']/*"/>
  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field,
     AllowMultiple=false, Inherited=true)]
  public class OptDefAttribute : Attribute
  {
    #region Members
    private OptValType _optionValueType;
    private Type       _valueType = null;
    #endregion Members

    #region Constructor
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="optionValueType">The type of value the option takes or null to use
    /// the type of the property/field</param>
    public OptDefAttribute(OptValType optionValueType)
    {
      _optionValueType = optionValueType;
    }
    #endregion Constructor

    #region Properties
    /// <summary>
    /// Get or set the type of value to support
    /// </summary>
    /// <remarks>
    /// For most properties and fields, this is optional (can be left null), but for
    /// IList types of properties that take multiple values, this property needs to be
    /// set to know how to convert the command-line values to the type the list expects
    /// </remarks>
    public Type ValueType 
    {
      get { return _valueType; }
      set { _valueType = value; }
    }


    /// <summary>
    /// Get the type of value the option takes
    /// </summary>
    public OptValType OptionValueType 
    {
      get { return _optionValueType; }
    }
    #endregion Properties
  }
  #endregion OptDefAttribute

  #region UseNameAsLongOptionAttribute
  /// <summary>
  /// Gives the ability to stop the name of a field or property being used
  /// to be used as an option name
  /// </summary>
  /// <remarks>
  /// By default, the name of a property or field is used as a option name
  /// when defined as an option (see <see cref="OptDefAttribute"/>). This
  /// attribute allows only names to be given using <see cref="LongOptionNameAttribute"/>
  /// and <see cref="ShortOptionNameAttribute"/> attributes. If this attribute value
  /// is false, one of the above attributes must be given for the property
  /// </remarks>
  /// <include file="ExternalDocs.xml" 
  ///    path="externalDocs/doc[@name='ExamplePropClass']/*"/>
  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field,
     AllowMultiple=false, Inherited=true)]
  public class UseNameAsLongOptionAttribute : Attribute
  {
    #region Members
    private bool _useName;
    #endregion Members

    #region Constructor
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="useName">Set to false to not use this field or property as
    /// a possible option name</param>
    public UseNameAsLongOptionAttribute(bool useName)
    {
      _useName = useName;
    }
    #endregion Constructor

    #region Properties
    /// <summary>
    /// Get if the name should be used as an option
    /// </summary>
    public bool UseName 
    {
      get { return _useName; }
    }
    #endregion Properties
  }
  #endregion UseNameAsLongOptionAttribute

  #region LongOptionNameAttribute
  /// <summary>
  /// Defines a long option for a field or property
  /// </summary>
  /// <remarks>This is only applicable if the field or property is marked as an option
  /// using <see cref="OptDefAttribute"/></remarks>
  /// <include file="ExternalDocs.xml" 
  ///    path="externalDocs/doc[@name='ExamplePropClass']/*"/>
  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field,
     AllowMultiple=true, Inherited=true)]
  public class LongOptionNameAttribute : Attribute
  {
    #region Members
    private string _name;
    #endregion Members

    #region Constructor
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="name">Name of the option</param>
    public LongOptionNameAttribute(string name)
    {
      _name = name;
    }
    #endregion Constructor

    #region Properties
    /// <summary>
    /// Get the name of the option
    /// </summary>
    public string Name 
    {
      get { return _name; }
    }
    #endregion Properties
  }
  #endregion LongOptionNameAttribute

  #region ShortOptionNameAttribute
  /// <summary>
  /// Defines a short option name for a field or property
  /// </summary>
  /// <remarks>This is only applicable if the field or property is marked as an option
  /// using <see cref="OptDefAttribute"/></remarks>
  /// <include file="ExternalDocs.xml" 
  ///    path="externalDocs/doc[@name='ExamplePropClass']/*"/>
  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field,
     AllowMultiple=true, Inherited=true)]
  public class ShortOptionNameAttribute : Attribute
  {
    #region Members
    private char _name;
    #endregion Members

    #region Constructor
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="name">Name of the option</param>
    public ShortOptionNameAttribute(char name)
    {
      _name = name;
    }
    #endregion Constructor

    #region Properties
    /// <summary>
    /// Get the name of the option
    /// </summary>
    public char Name 
    {
      get { return _name; }
    }
    #endregion Properties
  }
  #endregion ShortOptionNameAttribute
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.