ObjectList Class


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.  * FileName: objectList.cs
  3.  * Classes Included: objectList
  4.  * Purpose: The objectList is a class that contains Name-Value pairs that can be
  5.  * accessed as per the NameValueCollection, but the value is an arbitrary
  6.  * non-typed object that must be boxed on removal.
  7.  * Created on: 27 May 2009
  8.  * Created by: wraith808
  9.  *
  10.  * History:
  11.  * Date Who Note
  12.  * ---------------------------------------------------------------------------
  13.  * 05-27-2009 wraith808 Created
  14.  *
  15.  */
  16.  
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Text;
  20. using System.Collections.Specialized;
  21. using System.Collections;
  22.  
  23. namespace UtilsLib
  24. {
  25. public class objectList : NameObjectCollectionBase
  26. {
  27. // Creates an empty collection.
  28. public objectList()
  29. {
  30. }
  31.  
  32. // Adds elements from an IDictionary into the new collection.
  33. public objectList(IDictionary d, Boolean readOnly)
  34. {
  35. foreach ( DictionaryEntry de in d )
  36. {
  37. this.BaseAdd( (string) de.Key, de.Value );
  38. }
  39. this.IsReadOnly = readOnly;
  40. }
  41.  
  42. // Gets a key-and-value pair (DictionaryEntry) using an index.
  43. public DictionaryEntry this[ int index ]
  44. {
  45. get
  46. {
  47. return ( new DictionaryEntry(
  48. this.BaseGetKey(index), this.BaseGet(index) ) );
  49. }
  50. }
  51.  
  52. // Gets or sets the value associated with the specified key.
  53. public Object this[ string key ]
  54. {
  55. get
  56. {
  57. return( this.BaseGet( key ) );
  58. }
  59. set
  60. {
  61. this.BaseSet( key, value );
  62. }
  63. }
  64.  
  65. // Gets a String array that contains all the keys in the collection.
  66. public string[] AllKeys
  67. {
  68. get
  69. {
  70. return( this.BaseGetAllKeys() );
  71. }
  72. }
  73.  
  74. // Gets an Object array that contains all the values in the collection.
  75. public Array AllValues
  76. {
  77. get
  78. {
  79. return( this.BaseGetAllValues() );
  80. }
  81. }
  82.  
  83. // Gets a String array that contains all the values in the collection.
  84. public string[] AllStringValues
  85. {
  86. get
  87. {
  88. return( (string[]) this.BaseGetAllValues( typeof( string ) ));
  89. }
  90. }
  91.  
  92. // Gets a value indicating if the collection contains keys that are not null.
  93. public Boolean HasKeys
  94. {
  95. get
  96. {
  97. return( this.BaseHasKeys() );
  98. }
  99. }
  100.  
  101. // Adds an entry to the collection.
  102. public void Add( string key, Object value )
  103. {
  104. this.BaseAdd( key, value );
  105. }
  106.  
  107. // Removes an entry with the specified key from the collection.
  108. public void Remove( string key )
  109. {
  110. this.BaseRemove( key );
  111. }
  112.  
  113. // Removes an entry in the specified index from the collection.
  114. public void Remove( int index )
  115. {
  116. this.BaseRemoveAt( index );
  117. }
  118.  
  119. // Clears all the elements in the collection.
  120. public void Clear()
  121. {
  122. this.BaseClear();
  123. }
  124. }
  125. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.