I have a new wrinkle in something I thought was working previously, but now it seems to be not be working.
I have some properties that are being added dynamically to my objects at runtime via ICustomTypeDescriptor. Just recently, it seems, these have started throwing exceptions in the rule handling because no PropertyInfo is being returned for the property.
I dug a little deeper, and sure enough my ICustomTypeDescriptor methods aren't even being called when the property is being interrogated, however they get called when a collection of the objects is bound to a grid control.
Are custom properties provided via ICustomTypeDescriptor supported in CSLA? Maybe I just inadvertently broke something.
The exception is coming from the rules in CommonRules? That could be, because the code in those rules get the property value using reflection off the Type, not the TypeDescriptor. My guess is that only the TypeDescriptor honors ICustomTypeDescriptor (guessing based on the name similarlity ;) ).
If this is true (and I suspect it is), it might be a candidate for a future enhancement to CommonRules - to switch to using a TypeDescriptor to get the value rather than the Type.
Is this C# or VB? I ask because the VB code uses a VB runtime function to get the value, while in C# I had to replicate the VB function myself. If it were to work in VB and not C# (and it could easily work in VB), that'd indicate that I didn't totally replicate their behavior.
This is in C#, and the exception actually occurs in CallByName in Utilities when you are trying to retrieve the property value:
case CallType.Get:
{
PropertyInfo p = target.GetType().GetProperty(methodName);
return p.GetValue(target, args);
}
(p above is returned as null)
I don't see how I could have missed that calls using the Type don't honor ICustomTypeDescriptor, but I must have. Otherwise... (cue Rod Serling Twilight Zone music here)
It makes sense, since you don't have an instance when you use the Type, but I thought the framework was pulling a rabbit out of the hat to make it work. We just switched from VS 2005 to 2008 in the last month, which makes me wonder if something undocumented changed between them.
I don’t know what would have changed from 2005 to 2008,
but you never know.
Certainly I’d expect you’d need to use
TypeDescriptor instead of Type to get at your dynamic properties.
I’ll add this to the wish list for a future enhancement
(3.5.1 or something).
Rocky
Copyright (c) Marimer LLC