This repository has been archived on 2025-09-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Password-Manager-Legacy/Password Manager/Profiles/ProfileList.cs

64 lines
1.4 KiB
C#
Raw Normal View History

2023-03-24 11:14:49 +01:00
using System;
namespace Password_Manager
{
2023-03-24 12:01:08 +01:00
sealed class ProfileList : IList<Profile>
2023-03-24 11:14:49 +01:00
{
2023-03-24 12:01:08 +01:00
public ProfileList() : base() { }
2023-03-24 11:14:49 +01:00
2023-03-24 12:01:08 +01:00
public override void Add(Profile p)
2023-03-24 11:14:49 +01:00
{
//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;
}
2023-03-24 12:01:08 +01:00
public override void Remove(Profile p)
2023-03-24 11:14:49 +01:00
{
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;
}
2023-03-24 12:01:08 +01:00
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;
}
}
2023-03-24 11:14:49 +01:00
}
}