72 lines
1.6 KiB
C#
72 lines
1.6 KiB
C#
namespace Profiles
|
|
{
|
|
sealed class ProfileList : IList<Profile>
|
|
{
|
|
public ProfileList() : base() { }
|
|
|
|
public override void Add(Profile p)
|
|
{
|
|
//grow the list by 1 and copy all existing items
|
|
Profile[] tmp = new Profile[this.Length + 1];
|
|
|
|
for (int i = 0; i < this.Length; i++)
|
|
{
|
|
tmp[i] = this[i];
|
|
}
|
|
|
|
this.list = tmp;
|
|
|
|
//--------------------------------------------------------
|
|
|
|
list[this.Length - 1] = p;
|
|
}
|
|
|
|
public override void Remove(Profile p)
|
|
{
|
|
Profile[] tmp = new Profile[this.Length - 1];
|
|
|
|
for (int i = 0; i < tmp.Length; i++)
|
|
{
|
|
if (this[i] != p)
|
|
{
|
|
tmp[i] = this[i];
|
|
}
|
|
}
|
|
|
|
this.list = tmp;
|
|
}
|
|
|
|
public override Profile SearchByName(string name)
|
|
{
|
|
Profile? result = null;
|
|
|
|
for (int i = 0; i < this.Length; i++)
|
|
{
|
|
if (this[i].Name == name)
|
|
{
|
|
result = this[i];
|
|
}
|
|
}
|
|
|
|
if (result == null)
|
|
{
|
|
throw new ProfileNotFoundException();
|
|
}
|
|
else
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public string[] GetNameList()
|
|
{
|
|
string[] array = new string[this.Length];
|
|
for (int i = 0; i < this.Length; i++)
|
|
{
|
|
array[i] = this[i].Name;
|
|
}
|
|
return array;
|
|
}
|
|
}
|
|
}
|