Missing properties in object data source for a generic LineItem class

Missing properties in object data source for a generic LineItem class

Old forum URL: forums.lhotka.net/forums/t/4399.aspx


stefan posted on Saturday, February 23, 2008

When building a new object data source based on one of my classes,
I notice that the properties of  the class which is topmost in my inheritance hierarchy
are missing.

I will show you my class hierarchy.
It represents the well known Order-OrderLineItems-OrderLineItem structure:

Public Class Order
 mLineItems As OrderLineItems

The list hierarchy:
 
Public Class OrderLineItems
 Inherits MyAppLineItems(Of OrderLineItem)
 
 Public MustInherit Class MyAppLineItems(Of T As MyAppLineItem(Of T))
   Inherits MyBusinessListBase(Of MyAppLineItems(Of T), MyAppLineItem(Of T))
 
  Public MustInherit Class MyBusinessListBase(Of T As MyBusinessListBase(Of T, C), C As MyBusinessBase(Of C))
    Inherits Csla.BusinessListBase(Of T, C)
 
The lineItem hierarchy:
 
Public Class OrderLineItem
 Inherits MyAppLineItem(Of OrderLineItem)
 
 Public MustInherit Class MyAppLineItem(Of T)
   Inherits MyBusinessBase(Of MyAppLineItem(Of T))

  Public MustInherit Class MyBusinessBase(Of T As MyBusinessBase(Of T))
    Inherits Csla.BusinessBase(Of T)

I only see the Properties of MyAppLineItem(Of T). I expect to also see any public properties of OrderLineItem.

Maybe I have messed up my generic class declarations...

Any help would be greatly appreciated!

@Andy: I think this is something for you, as beeing the "LineItem guru"  ;-)

Stefan

ajj3085 replied on Monday, February 25, 2008

Hi,

I had similar problems.  In your base line item class, you'll need to implement ICustomTypeDescriptor.

Just be sure not to hardcode a typeof( ) function when you're implementing the interface, always use the GetType method.  That way, you're getting the final subclass, not the base class.

HTH
Andy

stefan replied on Monday, February 25, 2008

Thank you Andy for your response.

I somehow cannot believe that ICustomTypeDescriptor will solve my issue. (I am 'googleing' right now...) I want to get an explanation for the behaviour I am seeing, which is the WinFormsDesigner (or better the DataSourceExplorer) stopping to see properties in the middle of a class hierarchy...

I much more expect my generic classes beeing the source of the problem.

Maybe I could rework this. Knowing that you have implemented objects like SubTotalLineItem, PackingfeeLineItem etc., may I ask you how you did achieve this kind of polymorphism in your LineItemsCollection?
I thought that, for databinding to work with our Csla business objects, keeping our lists strongly typed was mandatory.

Could you just give me a hint. Maybe I could make my LineItem classes a bit less complex.

Thanks,
Stefan

ajj3085 replied on Monday, February 25, 2008

Well, it might not help if you're expecting to see something in the designer.  It may though, because in my reporting services client side reports I would use properties on specialized line items, and these wouldn't work with the report (I got an #Error whenever I tried to put the value on the report) until I implemented ICustomTypeDescriptor.  I think there's also an article somewhere that says you need to do this if your list holds a base class with mixed subtypes. 

The problem I had was very weird; if a certain type of line item was FIRST in the list of items on the report, everything was fine.  If it was second, it would display #Error.  I think the very first line item dictated what ALL the rest of the items in the list would look like (ie. it assumed the first item's type woudl be the type for ALL items in the list).  The only solution was to implement ICustomTypeDescriptor.

So, I'd try it.  Its very easy to implement; its just a bunch of one line impelementations that use PropertyDescriptor to do all the real work. 

On the other side of the coin, I never expect to see properties that only exist on a particular subclass.  I have somewhat virtual "properties" which right now are only boolean flags.  I build a context menu when a particular line item is selected and this building queries the line item though an API... but that API is common to all line items, so any line item can have such flags.

But nothing in the designer for my application is something that isn't really common to all line items.

stefan replied on Monday, March 03, 2008

I rebuilt my Document-LineItemList-LineItem structure from scratch in a separate testproject and - voilá, I found the mistake I made in the generic class declarations.
For the sake of completeness, I will show the resulting class signatures:

Public Class Order
 Private mLineItems As OrderLineItems

...

The list hierarchy:
 
Public Class OrderLineItems
 Inherits MyAppLineItems(Of
OrderLineItems, OrderLineItem)
 
Public MustInherit Class MyAppLineItems(Of T As
MyAppLineItems(Of T, C), C As MyAppLineItem(Of C))
   Inherits MyBusinessListBase(Of T, C)


Public MustInherit Class MyBusinessListBase(Of T As MyBusinessListBase(Of T, C), C As MyBusinessBase(Of C))
    Inherits Csla.BusinessListBase(Of T, C)


The lineItem hierarchy:
 
Public Class OrderLineItem
 Inherits MyAppLineItem(Of OrderLineItem)
 
 Public MustInherit Class MyAppLineItem(Of T As
MyAppLineItem(Of T))
   Inherits MyBusinessBase(Of T))

  Public MustInherit Class MyBusinessBase(Of T As MyBusinessBase(Of T))
    Inherits Csla.BusinessBase(Of T)


Now the resulting datasource is providing all the properties of all three levels.

For clarification:
The "MyApp..." level classes implement the interfaces needed for my lineitems to work properly (common LineItem properties, a parent reference etc.)
and the "MyBusiness..." level classes implement interfaces needed for my custom authorization.

Stefan





Copyright (c) Marimer LLC