Wouldn't it be nice if SetProperty method returned bool which would indicate if property value was actually modified ? So we could write code like this:
public string Dummy
{
get {.....}
set
{
if (SetProperty<string>(DummyProperty, value))
doSomething();
}
}
ie. setter could trigger some action when Dummy property actually gets a new value....
Or better yet, use the business rules functionality already in CSLA:
private static bool DoSomething<T>(T target, RuleArgs e) where T : YourClass
{
// here you can manipulate target (the business object)
// however you'd like in response to the property
// having changed
return true; // this rule is never broken, it just does work
}
Put your work in this method, then attach the method to the property and it just works.
It's just that, at least to me, setters seem like a good place for this kind of code, more straightforward and intuitive than creating a business rule handler to run it. But it's not really a problem, sure it can be done through business rules functionality, or even within the setter (we can still "manually" compare new and old value of the property...)
I don’t disagree that setters are a good place for this type
of code.
But my goal with CSLA since version 2.0 has been to standardize
property code to make properties “expendable”. Make it so you can
use snippets or code-gen to create and recreate property declarations without
risk of losing any meaningful behavior.
This is important, because code in a property setter can’t
easily be reused across different classes. If you find that a given property
needs to exist in multiple object types (which is fairly common), it is relatively
easy to reuse business/validation rules, but hard to reuse custom code in a
getter/setter.
Rocky
From: robert_m
[mailto:cslanet@lhotka.net]
Sent: Wednesday, July 02, 2008 7:07 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] A tiny teeny suggestion
It's just that, at least to me, setters seem like a good place for this
kind of code, more straightforward and intuitive than creating a business rule
handler to run it. But it's not really a problem, sure it can be done through
business rules functionality, or even within the setter (we can still
"manually" compare new and old value of the property...)
Copyright (c) Marimer LLC