I have created this generic method
public IEnumerable<T> GetByID<T>(IEnumerable<T> source, int id) where T : IFields
{
return source.Where(x => x.id == id);
}
where the IFieds
interface is
public interface IFields
{
string code { get; set; }
int id { get; set; }
}
when i try to get the value, this obviously won't compile
DB.GetByID(Helper.Database.Table<Items>(), 1);
with the following compile error.
The type "Items" cannot be used as type parameter "T" in the generic type or method "DB.GetByID(System.Collections.Generic.IEnumerable, int)". There is no implicit reference conversion from "Items" to "IFields"
How can i fix that? Actually, i wish to use lambda expression "in an anonymous type".