OptionResultsDictionary.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 » OptionResultsDictionary.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.Collections;

namespace CommandLine.OptParse{
  /// <summary>
  /// Dictionary of option results
  /// <seealso cref="DictionaryParserHelper"/>
  /// <seealso cref="ParserFactory.BuildParser(OptionDefinition[], 
  ///    OptionResultsDictionary)"/>
  /// </summary>
  /// <remarks>
  /// When using the <see cref="DictionaryParserHelper"/>, the helper will
  /// use this class to store the results of option parsing in an instance
  /// of this class.
  /// </remarks>
  public class OptionResultsDictionary : DictionaryBase
  {
    #region Members
    private Hashtable _indexedByID = new Hashtable();
    #endregion Members

    #region Methods
    /// <summary>
    /// Add a result
    /// </summary>
    /// <param name="key">Option definition</param>
    /// <param name="value">Result value</param>
    public void Add(OptionDefinition key, OptionResult value)
    {
      base.Dictionary.Add(key, value);
    }
    #endregion Methods
    
    #region Properties
    /// <summary>
    /// Get or set result by definition
    /// </summary>
    public OptionResult this[OptionDefinition key]
    {
      get { return (OptionResult)base.Dictionary[key]; }
      set { base.Dictionary[key] = value; }
    }


    /// <summary>
    /// Get the result by the ID of a definition
    /// </summary>
    public OptionResult this[object ID]
    {
      get { return (OptionResult)_indexedByID[ID]; }
    }
    #endregion Properties

    #region Overrides
    /// <summary>
    /// Validate the type of the key and value
    /// </summary>
    protected override void OnValidate(object key, object value)
    {
      if ((key is OptionDefinition) == false)
        throw new ArgumentException("Key must be OptionDefinition");
      if ((value is OptionResult) == false)
        throw new ArgumentException("Value must be OptionResult");

      base.OnValidate (key, value);
    }


    /// <summary>
    /// Update the inner index hashtables
    /// </summary>
    protected override void OnClearComplete()
    {
      _indexedByID.Clear();
      base.OnClearComplete ();
    }


    /// <summary>
    /// Update the inner index hashtables
    /// </summary>
    protected override void OnInsertComplete(object key, object value)
    {
      base.OnInsert (key, value);
      _indexedByID[((OptionDefinition)key).ID] = value;
    }


    /// <summary>
    /// Update the inner index hashtables
    /// </summary>
    protected override void OnRemoveComplete(object key, object value)
    {
      base.OnRemoveComplete (key, value);
      _indexedByID[((OptionDefinition)key).ID] = value;
    }


    /// <summary>
    /// Update the inner index hashtables
    /// </summary>
    protected override void OnSetComplete(object key, object oldValue, object newValue)
    {
      base.OnSetComplete (key, oldValue, newValue);
      _indexedByID[((OptionDefinition)key).ID] = newValue;
    }
    #endregion Overrides
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.