ReadProperty overloads <> GetProperty overloadsReadProperty overloads <> GetProperty overloads
Old forum URL: forums.lhotka.net/forums/t/7171.aspx
skagen00 posted on Thursday, June 25, 2009
Am I missing an obvious reason why these overloads aren't consistent?
When programming a business rule that may apply to multiple properties I end up with e.PropertyName ... I could do a "GetProperty" but that's really not my aim... I'd preferably use ReadProperty in my validation rules in practice.
I notice that the common rule code does this:
string value = (string)Utilities.CallByName(
target, e.PropertyName, CallType.Get);
CallByName does this:
case CallType.Get:
{
PropertyInfo p = target.GetType().GetProperty(methodName);
return p.GetValue(target, args);
}
Anyways, my basic question is... is there a particular reason why ReadProperty doesn't support the same overloads as GetProperty?
skagen00 replied on Thursday, June 25, 2009
I guess GetProperty doesn't provide an overload when using the property name alone either.
So when one simply has the property name (like in a validation rule) it seems a little cumbersome to get the value of that property unless I'm missing the obvious.
In my first encounter with this I just had an if/then on the various properties using the rule in my class (is e.PropertyName == "HomePhone", etc) but it would have been nice to just get the value using the name of the property. ajj3085 replied on Friday, June 26, 2009
You can do:
e.PropertyName == HomePhoneProperty.Name
Or are you asking for something else?skagen00 replied on Friday, June 26, 2009
Something else - it's just a minor thing really when only one class is involved - one can do branching based on the property name to get the value. Since many of these sorts of rules are private to the class it's not a big deal.
I suspect it's more of a backwards compatibility sort of thing but it'd be nice to have a reference to the actual propertyinfo instead of just e.PropertyName. From PropertyInfo I can get name, friendly name, any custom attributes if I declare a subclassed PropertyInfo for my use, can use read/load/get/set property as necessary, etc.
But yes, I'm using that sort of logic in my rule classes right now - I just wondered if I was missing a cleaner manner of dealing with it. (esp when it comes to rules that apply to multiple properties across different classes/aka common rules)Copyright (c) Marimer LLC