public class DupeChecks
{
public class DupeChecksStrings
{
private List<string> _dupeChecks;
private bool _ignoreCase;
public bool IgnoreCase
{
get { return _ignoreCase; }
set { _ignoreCase = value; }
}
public DupeChecksStrings()
{
_dupeChecks = new List<string>();
_ignoreCase = true;
}
public bool Has(string str)
{
bool rv = false;
foreach (string _dupeCheck in _dupeChecks)
{
if (_ignoreCase)
{
if (_dupeCheck.ToLower() == str.ToLower())
{
rv = true;
}
}
else
{
if (_dupeCheck == str)
{
rv = true;
}
}
}
if (!rv)
{
_dupeChecks.Add(str);
}
return rv;
}
}
public class DupeChecksInts
{
private List<int> _dupeChecks;
public DupeChecksInts()
{
_dupeChecks = new List<int>();
}
public bool Has(int i)
{
bool rv = false;
foreach (int _dupeCheck in _dupeChecks)
{
if (_dupeCheck == i)
{
rv = true;
}
}
if (!rv)
{
_dupeChecks.Add(i);
}
return rv;
}
}
public class ByObject
{
private List<object> store;
public ByObject()
{
store = new List<object>();
}
public List<object> DeDupe(List<object> source, string propertyName)
{
if (source.Count > 0)
{
Type type = source[0].GetType();
PropertyInfo[] sourceProperties = type.GetProperties();
bool foundProperty = false;
foreach (PropertyInfo sourceProperty in sourceProperties)
{
if (sourceProperty.Name == propertyName)
{
foundProperty = true;
}
}
if (foundProperty)
{
foreach (object obj in source)
{
if (!StoreHas(obj, propertyName))
{
store.Add(obj);
}
}
}
}
return store;
}
private bool StoreHas(object item, string propertyName)
{
bool rv = false;
Type itemType = item.GetType();
PropertyInfo[] itemPIs = itemType.GetProperties();
foreach (object obj in store)
{
Type storeType = obj.GetType();
foreach (PropertyInfo storePI in storeType.GetProperties())
{
if (storePI.Name == propertyName)
{
foreach (PropertyInfo itemPI in itemPIs)
{
if (itemPI.Name == propertyName)
{
if (itemPI.GetValue(item, null).ToString() == storePI.GetValue(obj, null).ToString())
{
rv = true;
}
}
}
}
}
}
return rv;
}
}
}