Reputation: 37
I have a List object that I need to be able to swap the object type dynamically. Basically I have:
List<DataBaseItems> items = new List<DataBaseItems>();
I will then perform some filtering on that list with LINQ then bind to a telerik grid. I need to swap out the object based on an id that i get. My goal is to build a custom control that can use it's filter button for multiple reports where the report data is coming from the above list. Report A may use the above list and report B needs a completely different object but has the same actions on it.
Upvotes: 0
Views: 108
Reputation: 2602
public interface ICustomListFilter<T>
where T:class
{
public void FilterAndBindMyList(List<T> myList);
}
public class ReportOneFilter:ICustomListFilter<MyFirstType>
{
public void FilterAndBindMyList(List<MyFirstType> items)
{
// your filtering and binding code goes here, such as items.Where(i => ...
}
}
public class ReportTwoFilter:ICustomListFilter<MySecondType>
{
public void FilterAndBindMyList(List<MySecondType> items)
{
// your another filtering and binding algorithm goes here, such as items.Select(i => ...
}
}
Upvotes: 0
Reputation: 1999
Create an interface and implement it into whatever objects you implement.
Upvotes: 1