foreach (Customer c in results) {
Console.WriteLine(c.name);
}
Console.Read();
}
}
class Customer {
public string name;
public Customer(string name) {
this.name = name;
}
}
class ListSearcher<T>{
Type type;
public ListSearcher() {
type = typeof(T);
}
public T[] SearchField(List<T> lists, string fieldname, string keyword)
{
System.Reflection.FieldInfo field = type.GetField(fieldname);
List<T> results = new List<T>();
foreach(T c in lists){
string value = field.GetValue(c) as string;
if (value.IndexOf(keyword) != -1) {
results.Add(c);
}
}
return results.ToArray();
}
}
}