How to add a property to a listbase

How to add a property to a listbase

Old forum URL:

swegele posted on Thursday, February 02, 2012

Ugh...I've used CSLA for over 7 years and I can't answer this silly question.

I have a BusinessListBase (root) and I want to add a property on it.  It looks like that doesn't have the nice helpful PropertyInfo / RegisterProperty etc.

How would I ensure my property serializes?

The property is a Guid



swegele replied on Thursday, February 02, 2012

OK OK it just occurred to me that the need for a property on a collection is telling me I need a parent BusinessBase with that property and the collection becomes a child collection.

Sorry Smile

Peran replied on Monday, February 06, 2012

If you don't need business rules attached to the properties you can override Csla.Serialization.Mobile.IMobileObject on BusinessListBase.


public DateTime FromDate { get; set; }

public DateTime ToDate { get; set; }


protected override void OnGetState(Csla.Serialization.Mobile.SerializationInfo info)


info.AddValue(ObjectPropertyName.FromDate, this.FromDate);

info.AddValue(ObjectPropertyName.ToDate, this.ToDate);





protected override void OnSetState(Csla.Serialization.Mobile.SerializationInfo info)


this.FromDate = info.GetValue<DateTime>(ObjectPropertyName.FromDate);

this.ToDate = info.GetValue<DateTime>(ObjectPropertyName.ToDate);




swegele replied on Monday, February 06, 2012

Thanks Peran,

You are right on how to get a property on a BusinessListBase and that is what I asked. 

But I found myself wondering "Why isn't that ability built into the BusinessListBase already?"  I mean if it is a valid need, then usually Rocky et al. will put that ability in the object.

The problem is not with BusinessListBase...the problem was with my design.  Trying to make BusinessListBase do a behavior that it wasn't meant for.

When I find myself walking down a road alone, I have to pause and ask why isn't anyone else here.  While there is a valid case for pioneers and path must be careful to be sure.  The CSLA framework and community is a sanity check for me as I code.  When I don't find ANY posts on people trying to put properties on BusinessListBase then I seriously have to think why the heck am I trying to do it. 

At least in my case it was because I wasn't seeing I needing a root BusinessBase with the property that applied to all the children in the collection.

Scary how dumb I am sometimes after all these years of programming.

But Rocky's (or David West's) mantra of "Design your objects after behavior not data" is finally beginning to sink in.

Thanks again Peran!  Good coding.

Copyright (c) Marimer LLC