Drawbacks to not using LoadProperty and ReadProperty for read only fields?

Drawbacks to not using LoadProperty and ReadProperty for read only fields?

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


raz0rf1sh posted on Wednesday, April 15, 2009

We have a business object called Invoice. An invoice is tied to a Customer, and in our object we also bring in the CustomerName. When the CustomerId changes we update the CustomerName. Is there any need/benefit to using the LoadProperty and ReadProperty instead of just doing something like:

public string CustomerName
{
get;
internal set;
}

Just trying to eliminate some code, that might not me needed.

Saving them pixels! =)

ajj3085 replied on Wednesday, April 15, 2009

It depends; are you using private fields to store the value? If not, LoadProperty is what you should be using. The public Get if you use GetProperty will make it easier if you ever add authorization rules.

RockfordLhotka replied on Wednesday, April 15, 2009

And if you ever decide to move to Silverlight, using private backing fields will require that you manually serialize/deserialize those values.

ajj3085 replied on Friday, April 17, 2009

I think I know the answer, but just want to be clear. Lets say you have a flag in a BO and you may use this BO in Silverlight. The flag affects how the object works, but its never exposed outside the class at all. Would the recommended pattern be to have a RegisterProperty and a private property on the class, so that the value automatically serializes / deserializes? I have a few classes which such fields, so i'm trying to figure out the best future-safe method to do so.

RockfordLhotka replied on Friday, April 17, 2009

That would be the easiest solution, yes.

Alternately, you could store the value in a private field, and then override
OnGetState() and OnSetState() to manually include it in the serialization
stream.

Rocky


-----Original Message-----
From: ajj3085 [mailto:cslanet@lhotka.net]
Sent: Friday, April 17, 2009 12:58 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Drawbacks to not using LoadProperty and
ReadProperty for read only fields?

I think I know the answer, but just want to be clear. Lets say you have a
flag in a BO and you may use this BO in Silverlight. The flag affects how
the object works, but its never exposed outside the class at all. Would the
recommended pattern be to have a RegisterProperty and a private property on
the class, so that the value automatically serializes / deserializes? I
have a few classes which such fields, so i'm trying to figure out the best
future-safe method to do so.

Copyright (c) Marimer LLC