0

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.

1
  • Use generics, OR add a common interface that is supported by all the objects you want to use in such a list/situation, and program against the interface instead of the concrete objects. OR use reflection. Commented Jul 18, 2014 at 15:21

2 Answers 2

1

Create an interface and implement it into whatever objects you implement.

Sign up to request clarification or add additional context in comments.

Comments

0
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 => ...
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.