A couple questions regarding property usage.

A couple questions regarding property usage.

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


Dane posted on Friday, March 19, 2010

1.  When using an ObjectFactory you can load a property without incurring the overhead of checking rules by using either LoadProperty or BypassPropertyChecks.  Is there an advantage to using one over the other?

2. From within a business object class do you need to use ReadProperty and LoadProperty to avoid rules checking, e.g. inside a business object class method if I do this will it check validation rules?

int i = this.FooIntegerProperty;

RockfordLhotka replied on Friday, March 19, 2010

Dane

1.  When using an ObjectFactory you can load a property without incurring the overhead of checking rules by using either LoadProperty or BypassPropertyChecks.  Is there an advantage to using one over the other?

There's no direct advantage to one over the other - they both do the same thing. But if your property is read-only (has a non-public setter) then only LoadProperty() will work because the factory object can't set the property otherwise.

I tend to use BypassPropertyChecks by default, because I like the readability of just setting the properties, but for read-only properties the only answer is LoadProperty().

Dane

2. From within a business object class do you need to use ReadProperty and LoadProperty to avoid rules checking, e.g. inside a business object class method if I do this will it check validation rules?

int i = this.FooIntegerProperty;

Inside the object you can use ReadProperty()/LoadProperty(), or BypassPropertyChecks - either option works here as well. And inside your object you typically don't have to worry about read-only properties, because you can have a private or protected setter. At least that's my typical approach.

Copyright (c) Marimer LLC