Rev | Line | |
---|
[2769] | 1 | using System;
|
---|
| 2 | using System.Collections;
|
---|
| 3 | namespace Netron.GraphLib.IO.NML
|
---|
| 4 | {
|
---|
| 5 | /// <summary>
|
---|
| 6 | /// STC of string-value pairs, helpful in keeping a collection of properties with their value
|
---|
| 7 | /// </summary>
|
---|
| 8 | public class PropertiesHashtable : DictionaryBase
|
---|
| 9 | {
|
---|
| 10 | /// <summary>
|
---|
| 11 | /// keeps the collection of keys
|
---|
| 12 | /// </summary>
|
---|
| 13 | private StringCollection mKeys = new StringCollection();
|
---|
| 14 |
|
---|
| 15 | /// <summary>
|
---|
| 16 | /// Gets the keys of the hashtable and
|
---|
| 17 | /// allows to loop over the keys without
|
---|
| 18 | /// boxing/unboxing.
|
---|
| 19 | /// </summary>
|
---|
| 20 | public StringCollection Keys
|
---|
| 21 | {
|
---|
| 22 | get{return mKeys;}
|
---|
| 23 |
|
---|
| 24 | }
|
---|
| 25 | /// <summary>
|
---|
| 26 | /// Constructor
|
---|
| 27 | /// </summary>
|
---|
| 28 | public PropertiesHashtable()
|
---|
| 29 | {
|
---|
| 30 |
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | /// <summary>
|
---|
| 36 | /// Adds a property-value pair
|
---|
| 37 | /// </summary>
|
---|
| 38 | /// <param name="key"></param>
|
---|
| 39 | /// <param name="propertyValue"></param>
|
---|
| 40 | public void Add(string key, object propertyValue)
|
---|
| 41 | {
|
---|
| 42 | this.InnerHashtable.Add(key, propertyValue);
|
---|
| 43 | mKeys.Add(key);
|
---|
| 44 | }
|
---|
| 45 | /// <summary>
|
---|
| 46 | /// Integer indexer
|
---|
| 47 | /// </summary>
|
---|
| 48 | public object this[int index]
|
---|
| 49 | {
|
---|
| 50 | get{
|
---|
| 51 |
|
---|
| 52 | if(mKeys[index]!=null)
|
---|
| 53 | {
|
---|
| 54 | return this.InnerHashtable[mKeys[index]];
|
---|
| 55 | }
|
---|
| 56 | else return null;
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | /// <summary>
|
---|
| 61 | /// Removes an elements based on a key
|
---|
| 62 | /// </summary>
|
---|
| 63 | /// <param name="key">a (string) key</param>
|
---|
| 64 | /// <returns></returns>
|
---|
| 65 | public bool Remove(string key)
|
---|
| 66 | {
|
---|
| 67 | int index;
|
---|
| 68 | if((index=mKeys.Contains(key))>-1)
|
---|
| 69 | {
|
---|
| 70 | this.InnerHashtable.Remove(key);
|
---|
| 71 | this.mKeys.RemoveAt(index);
|
---|
| 72 | return true;
|
---|
| 73 | }
|
---|
| 74 | return false;
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.