RegisterProperty on ReadOnlyListBase??

RegisterProperty on ReadOnlyListBase??

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


dshafer posted on Friday, March 20, 2009

Please forgive me if this should be obvious.  I have very little experience with the new "Managed Backing Fields" that were introduced in CSLA 3.5.  I'm currently designing my first CSLALight solution and I've run into a problem.  Here's my scenario:

1.  I have a class named EntitlementInfo that inherits from ReadOnlyBase and has a property (using the Managed Backing Field" approach) named HoursEntitled.

2.  I have a list class named EntitlementInfoList that inherits from ReadOnlyListBase.  I would like to add a property on this class that would hold the sum of the HoursEntitled property for all of the items in the list.

The actual process of getting the total isn't my main concern at the moment.  I'm having a problem when I try to create the TotalHoursEntitled property on the EntitlementInfoList class.  I'm trying to use the same "Managed Backing Field" approach that I used for the EntitlementInfo class, but I get a compiler error that says basically that the RegisterProperty method  is not found.  Then I tried the regular private field public property way, but it appears as though the value in the TotalHoursEntitled property isn't serialized through the WCF service.  How do I create a property on the EntitlementInfoList and have it serialize the data through the service to the Silverlight client?

Thanks,

Dustin

RockfordLhotka replied on Friday, March 20, 2009

In general, CSLA doesn't support the idea of putting properties on lists, because data binding doesn't support that concept.

You can (must) put that value into a normal private field if you want to store it in the list. There's no problem with doing that.

If you want the value to serialize across the wire (and you might find it easier to just recalc the value on deserialization instead), you'll need to override the OnGetState() and OnSetState() methods in the list class and get/set the property value into/out of the serialization stream. This is not hard to do for a primitive data type like a numeric or even string value.

But again, you might find that recalculating the value in an OnDeserialized() overload is easier than serializing the value over the wire.

dshafer replied on Friday, March 20, 2009

Rocky,

Thanks for the information.  I hadn't thought about the OnDeserialized approach.  I was just trying to find the cleanest and most correct way of doing it.  Besides the fact that the property on the list is not supported in databinding, are there any reasons why CSLA would not work with a custom
version of the RegisterProperty() method, similar to the one on ReadOnlyBase for use in ReadOnlyListBase?

Thanks,

Dustin

RockfordLhotka replied on Saturday, March 21, 2009

It is partially a size/perf thing. The field manager isn't entirely free - in that it has to be serialized, and thus it adds to the size of the byte stream over the wire. Since the normal behavior for a list is to just contain items, always having a field manager field would increase the serialized byte stream all the time, just for the convenience of using it the .001% of the time when a list needs a field.

So it is better, I think, to do a little extra work that .001% of the time to get the better result most of the time.

Copyright (c) Marimer LLC