开发者

CSLA, BusinessCollectionBase, and ITypedList

I'm working on a large Winforms project for a client that is using business objects modeled on pre-.NET 2.0 CSLA. Upgrading to a newer version of CSLA is not an option. My client uses CodeSmith to generate "base" CSLA-style business objects from database tables. All business objects come with a corresponding "List" class.

One of the problems I've run into is binding to Winforms controls, because the generated List classes do not implement ITypedList. I've been told by the client that I can extend the List classes and implement it myself (they provided the code snippet below), but am dealing with quite a few business objects, and am violating DRY every time I extend one of the List classes to implement ITypedList. I'm using the following code in every extended List class:

public class SomeItemListExtended : SomeItemListBase, ITypedList
{
    public string GetListName(PropertyDescriptor[] listAccessors)
    {
        return null;
    }

    public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
    {
        return TypeDescriptor.GetProperties(CreateContent().GetType());
    }
}

CreateContent simply returns a new instance of the item that the List is a collection of:

public BusinessBase CreateContent()
{
    return new SomeItem();
}

I've been trying to figure out if there's a way I can use inheritance to avoid having the same code duplicated in each List class extension, but haven't figured out how to do it without multiple inheritance, which we all know isn't possible anyway. If I create a ListExtensionBase class that implements ITypedList, my extension classes can't inherit from both ListExtensionBase and, in the example above, SomeItemListBase. If I create a base class with a generic parameter, I lose direct access to all of the base class members. I have no control over how SomeItemListBase is generated and have been instructed to use their business object framework as-is. Is there any way I can get around implementing ITypedList with the same code in every single List extension? S开发者_运维技巧hould I even be using the same code for each implementation, or should the ITypedList implementations be different for each extension?


Without being able to modify the base classes, I think your stuck with implementing ITypedList separately on each list class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜