C# – Need a method that accepts all kind of Subsonic Collections as a parameter

csubsonic

If I have a method that does something with multiple Subsonic ActiveRecords and doesn know what type exactly it is easy thanks to interfaces.

public void DoSomething(IActiveRecord item)
{
   // Do something
}

But what if you have a method and you don't know what Collection (e.g. ProductCollection) you get? How do I have to declare my Parameter? There is no IActiveList interface.

I tried it with an generic approach, but that doesn't compile.

public void Add<Titem, Tlist>(ActiveList<Titem, Tlist> list)
{
    foreach(IActiveRecord item in list)
    {
        // Do something
    }
}

Best Answer

You could limit the parameter to be a BindingListEx (the base class for AbstractList) and which would would give you an enumerable list:

public void <T>(T list) where T : BindingListEx<IActiveRecord>
{
    foreach(IActiveRecord item in list)
    {

    }
}