using System;
using System.Collections.Generic;
using System.Xml;
using System.Text;
namespace RolePlayingGameData
{
///
/// Extends NET framework classes with the methods missing on XBox
/// Implements only basic functionality of those methods
///
public static class MissingMethods
{
///
/// Implements List.RemoveAll(Predicate match) method
///
public static int RemoveAll(this List that, Predicate match)
{
int count = that.Count;
List res = new List(that.Count);
foreach (var item in that)
{
if (match(item) == false)
{
res.Add(item);
}
}
that.Clear();
that.AddRange(res);
return that.Count - count;
}
///
/// Implements List.Find(Predicate match) method
///
public static T Find(this List that, Predicate match)
{
foreach (var item in that)
{
if (match(item) == true)
{
return item;
}
}
return default(T);
}
///
/// Implements List.Exists(Predicate match) method
///
public static bool Exists(this List that, Predicate match)
{
foreach (var item in that)
{
if (match(item) == true)
{
return true;
}
}
return false;
}
///
/// Implements List.TrueForAll(Predicate match) method
///
public static bool TrueForAll(this List that, Predicate match)
{
foreach (var item in that)
{
if (match(item) == false)
{
return false;
}
}
return true;
}
///
/// Implements List.FindIndex(Predicate match) method
///
public static int FindIndex(this List that, Predicate match)
{
for (int i = 0; i < that.Count; i++)
{
if (match(that[i]) == true)
{
return i;
}
}
return -1;
}
///
/// Implements XmlReader.ReadElementString(string name) method
///
public static string ReadElementString(this XmlReader that, string name)
{
return that.ReadElementContentAsString();
}
}
}