#region License
/**
* Ingenious MVC : An MVC framework for .NET 2.0
* Copyright (C) 2006, JDP Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: - Kent Boogaart (kentcb@internode.on.net)
* - James Inge
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using Ingenious.Mvc.Util;
namespace Ingenious.Mvc.Configuration{
/// <include file='InfoCollection.doc.xml' path='/doc/member[@name="T:InfoCollection`2"]/*'/>
[Serializable]
public sealed class InfoCollection<TIdType, TInfoType> : ICollection<TInfoType>
where TInfoType : class, IInfo<TIdType>
{
private IDictionary<TIdType, TInfoType> _infos;
/// <include file='InfoCollection.doc.xml' path='/doc/member[@name="P:Item"]/*'/>
public TInfoType this[TIdType id]
{
get
{
if (_infos.ContainsKey(id))
{
return _infos[id];
}
return default(TInfoType);
}
}
/// <include file='InfoCollection.doc.xml' path='/doc/member[@name="P:IsReadOnly"]/*'/>
public bool IsReadOnly
{
get
{
return _infos.IsReadOnly;
}
}
/// <include file='InfoCollection.doc.xml' path='/doc/member[@name="P:Count"]/*'/>
public int Count
{
get
{
return _infos.Count;
}
}
/// <include file='InfoCollection.doc.xml' path='/doc/member[@name="M:.ctor()"]/*'/>
public InfoCollection()
{
_infos = new Dictionary<TIdType, TInfoType>();
}
/// <include file='InfoCollection.doc.xml' path='/doc/member[@name="M:Add()"]/*'/>
public void Add(TInfoType info)
{
ArgumentHelper.AssertNotNull(info, "info");
_infos[info.Id] = info;
}
/// <include file='InfoCollection.doc.xml' path='/doc/member[@name="M:AddRange()"]/*'/>
public void AddRange(ICollection<TInfoType> infos)
{
ArgumentHelper.AssertNotNull(infos, "infos");
foreach (TInfoType info in infos)
{
Add(info);
}
}
/// <include file='InfoCollection.doc.xml' path='/doc/member[@name="M:Clear()"]/*'/>
public void Clear()
{
_infos.Clear();
}
/// <include file='InfoCollection.doc.xml' path='/doc/member[@name="M:Contains()"]/*'/>
public bool Contains(TInfoType info)
{
ArgumentHelper.AssertNotNull(info, "info");
return _infos.Keys.Contains(info.Id);
}
/// <include file='InfoCollection.doc.xml' path='/doc/member[@name="M:CopyTo(,System.Int32)"]/*'/>
public void CopyTo(TInfoType[] array, int index)
{
_infos.Values.CopyTo(array, index);
}
/// <include file='InfoCollection.doc.xml' path='/doc/member[@name="M:Remove()"]/*'/>
public bool Remove(TInfoType info)
{
ArgumentHelper.AssertNotNull(info, "info");
return _infos.Remove(info.Id);
}
IEnumerator<TInfoType> IEnumerable<TInfoType>.GetEnumerator()
{
return _infos.Values.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return _infos.Values.GetEnumerator();
}
}
}
|