using System.Collections.Generic;
using System.Linq;
namespace ChatSharp
{
///
/// A filtered view of the user pool.
///
public class UserPoolView : IEnumerable
{
private IEnumerable Users { get; set; }
internal UserPoolView(IEnumerable users)
{
Users = users;
}
///
/// Gets the IrcUser with the specified nick.
///
public IrcUser this[string nick]
{
get
{
var user = Users.FirstOrDefault(u => u.Nick == nick);
if (user == null)
throw new KeyNotFoundException();
return user;
}
}
internal IrcUser this[int index]
{
get
{
return Users.ToList()[index];
}
}
///
/// Returns true if any user in the pool matches this mask. Note that not all users
/// in the user pool will be fully populated, even if you set ClientSettings.WhoIsOnJoin
/// to true (it takes time to whois everyone in your channels).
///
public bool ContainsMask(string mask)
{
return Users.Any(u => u.Match(mask));
}
///
/// Returns true if any user in the pool has the specified nick.
///
public bool Contains(string nick)
{
return Users.Any(u => u.Nick == nick);
}
///
/// Returns true if the given IrcUser is in the pool.
///
public bool Contains(IrcUser user)
{
return Users.Any(u => u.Hostmask == user.Hostmask);
}
///
/// Enumerates over the users in this collection (with the filter applied).
///
public IEnumerator GetEnumerator()
{
return Users.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
}