Return to Snippet

Revision: 15263
at October 26, 2011 01:48 by wraith808


Updated Code
/*
 * FileName: objectList.cs
 * Classes Included: objectList
 * Purpose: The objectList is a class that contains Name-Value pairs that can be
 *   accessed as per the NameValueCollection, but the value is an arbitrary
 *   non-typed object that must be boxed on removal.
 * Created on: 27 May 2009
 * Created by: wraith808
 * 
 * History:
 * Date         Who         Note
 * ---------------------------------------------------------------------------
 * 05-27-2009   wraith808   Created
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using System.Collections;

namespace UtilsLib
{
    public class objectList : NameObjectCollectionBase
    {
        // Creates an empty collection.
        public objectList()  
        {
        }

        // Adds elements from an IDictionary into the new collection.
        public objectList(IDictionary d, Boolean readOnly)
        {
            foreach ( DictionaryEntry de in d )  
            {
                this.BaseAdd( (string) de.Key, de.Value );
            }
            this.IsReadOnly = readOnly;
        }

        // Gets a key-and-value pair (DictionaryEntry) using an index.
        public DictionaryEntry this[ int index ]  
        {
            get  
            {
                return ( new DictionaryEntry( 
                    this.BaseGetKey(index), this.BaseGet(index) ) );
            }
        }

        // Gets or sets the value associated with the specified key.
        public Object this[ string key ]  
        {
            get  
            {
                return( this.BaseGet( key ) );
            }
            set  
            {
                this.BaseSet( key, value );
            }
        }

        // Gets a String array that contains all the keys in the collection.
        public string[] AllKeys  
        {
            get  
            {
                return( this.BaseGetAllKeys() );
            }
        }

        // Gets an Object array that contains all the values in the collection.
        public Array AllValues  
        {
            get  
            {
                return( this.BaseGetAllValues() );
            }
        }

        // Gets a String array that contains all the values in the collection.
        public string[] AllStringValues  
        {
            get  
            {
                return( (string[]) this.BaseGetAllValues( typeof( string ) ));
            }
        }

        // Gets a value indicating if the collection contains keys that are not null.
        public Boolean HasKeys  
        {
            get  
            {
                return( this.BaseHasKeys() );
            }
        }

        // Adds an entry to the collection.
        public void Add( string key, Object value )  
        {
            this.BaseAdd( key, value );
        }

        // Removes an entry with the specified key from the collection.
        public void Remove( string key )  
        {
            this.BaseRemove( key );
        }

        // Removes an entry in the specified index from the collection.
        public void Remove( int index )  
        {
            this.BaseRemoveAt( index );
        }

        // Clears all the elements in the collection.
        public void Clear()  
        {
            this.BaseClear();
        }
    }
}

Revision: 15262
at June 29, 2009 15:01 by wraith808


Initial Code
/*
 * FileName: objectList.cs
 * Classes Included: objectList
 * Purpose: The objectList is a class that contains Name-Value pairs that can be
 *   accessed as per the NameValueCollection, but the value is an arbitrary
 *   non-typed object that must be boxed on removal.
 * Created on: 27 May 2009
 * Created by: Charles Little
 * 
 * History:
 * Date         Initials    Note
 * ---------------------------------------------------------------------------
 * 05-27-2009   CWL         Created
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using System.Collections;

namespace UtilsLib
{
    public class objectList : NameObjectCollectionBase
    {
        // Creates an empty collection.
        public objectList()  
        {
        }

        // Adds elements from an IDictionary into the new collection.
        public objectList(IDictionary d, Boolean readOnly)
        {
            foreach ( DictionaryEntry de in d )  
            {
                this.BaseAdd( (string) de.Key, de.Value );
            }
            this.IsReadOnly = readOnly;
        }

        // Gets a key-and-value pair (DictionaryEntry) using an index.
        public DictionaryEntry this[ int index ]  
        {
            get  
            {
                return ( new DictionaryEntry( 
                    this.BaseGetKey(index), this.BaseGet(index) ) );
            }
        }

        // Gets or sets the value associated with the specified key.
        public Object this[ string key ]  
        {
            get  
            {
                return( this.BaseGet( key ) );
            }
            set  
            {
                this.BaseSet( key, value );
            }
        }

        // Gets a String array that contains all the keys in the collection.
        public string[] AllKeys  
        {
            get  
            {
                return( this.BaseGetAllKeys() );
            }
        }

        // Gets an Object array that contains all the values in the collection.
        public Array AllValues  
        {
            get  
            {
                return( this.BaseGetAllValues() );
            }
        }

        // Gets a String array that contains all the values in the collection.
        public string[] AllStringValues  
        {
            get  
            {
                return( (string[]) this.BaseGetAllValues( typeof( string ) ));
            }
        }

        // Gets a value indicating if the collection contains keys that are not null.
        public Boolean HasKeys  
        {
            get  
            {
                return( this.BaseHasKeys() );
            }
        }

        // Adds an entry to the collection.
        public void Add( string key, Object value )  
        {
            this.BaseAdd( key, value );
        }

        // Removes an entry with the specified key from the collection.
        public void Remove( string key )  
        {
            this.BaseRemove( key );
        }

        // Removes an entry in the specified index from the collection.
        public void Remove( int index )  
        {
            this.BaseRemoveAt( index );
        }

        // Clears all the elements in the collection.
        public void Clear()  
        {
            this.BaseClear();
        }
    }
}

Initial URL


Initial Description


Initial Title
ObjectList Class

Initial Tags


Initial Language
C#