/*
* Namespace Summary
* Copyright (C) 2005+ Bogdan Damian Constantin
* E-Mail: damianbcpetro@gmail.com
* WEB: http://www.sourceforge.net/projects/dataholder
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License 2.1 or later, as
* published by the Free Software Foundation. See the included License.txt
* or http://www.gnu.org/copyleft/lesser.html for details.
*
*/
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
namespace DataHolder.Containers.Property{
/// <summary>
/// Collection of all the properties for a specific property
/// </summary>
public sealed class PropertyCollection : ICollection, IEnumerable , ICloneable
{
private GenericDataProperty [] _Properties;
private Dictionary<string, int> PropNamesSpeeder;
public PropertyCollection(GenericDataProperty [] initProp)
{
if(initProp == null)
throw new Exceptions.DataHolderPropertyException("PropertyCollection Constructor parameter Error, Properties are not set");
_Properties = new GenericDataProperty[initProp.Length];
initProp.CopyTo(_Properties,0);
InitPropNamesSpeeder();
}
public PropertyCollection(PropertyCollection ExistingProperty, GenericDataProperty [] newProp)
{
if(newProp == null)
throw new Exceptions.DataHolderPropertyException("PropertyCollection Constructor parameter Error, Properties are not set");
_Properties = new GenericDataProperty[ExistingProperty.Count + newProp.Length];
ExistingProperty.CopyTo(_Properties, 0);
newProp.CopyTo(_Properties,ExistingProperty.Count);
InitPropNamesSpeeder();
}
private void InitPropNamesSpeeder()
{
PropNamesSpeeder = new Dictionary<string, int>(_Properties.Length);
for(int i = 0; i< _Properties.Length; i++)
PropNamesSpeeder[_Properties[i].PropertyName] = i;
}
#region ICollection Members
public bool IsSynchronized
{
get
{
return false;
}
}
public int Count
{
get
{
if(_Properties == null)
return 0;
else
return _Properties.Length;
}
}
public void CopyTo(Array array, int index)
{
if(_Properties == null)
return;
_Properties.CopyTo(array, index);
}
public object SyncRoot
{
get
{
if(_Properties == null)
return null;
else
return _Properties.SyncRoot;
}
}
#endregion
#region IEnumerable Members
public IEnumerator GetEnumerator()
{
return _Properties.GetEnumerator();
}
#endregion
#region List Members
public GenericDataProperty this[string PropName]
{
get
{
if(PropNamesSpeeder.ContainsKey(PropName))
return _Properties[PropNamesSpeeder[PropName]];
else
return null;
}
}
public GenericDataProperty this[int index]
{
get
{
return _Properties[index];
}
set
{
_Properties[index] = value;
}
}
public bool Contains(string value)
{
return PropNamesSpeeder.ContainsKey(value);
}
public int IndexOf(string value)
{
return PropNamesSpeeder[value];
}
#endregion
#region ICloneable Members
public object Clone()
{
PropertyCollection newPropColl = new PropertyCollection(_Properties);
return newPropColl;
}
#endregion
}
}
|