DataMapper GetPropertyValue request

DataMapper GetPropertyValue request

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


rfcdejong posted on Friday, April 03, 2009

The DataMapper has performance improvements because it works with cached property's and DynamicMemberHandle, and CSLA reflection is using the DynamicMethodHandlerFactory which uses ILGenerator.Emit

Extreme speed, which is nice :)  (good job!)

But i've a situation where i want to map specific property values from my data object to a dictionary, so i can use the dictionary later to go from dictionary to business object. The DataMapper.Map() has an exclusion parameter but that is in my situation overkill populating an exclusion set every time while i only want to read a few propertie values out an object.


Can the following code be added to the DataMapper?

#region GetValue

public static object GetPropertyValue(object target, string propertyName)
{
      
DynamicMemberHandle handle = MethodCaller.GetCachedProperty(target.GetType(), propertyName);
      
return handle.DynamicMemberGet(target);
}

#endregion

RockfordLhotka replied on Friday, April 03, 2009

I believe you can already do that using Utilities.CallByName().

DataMapper has one responsibility - which is to map properties from one object to another. If we need an object that exposes basic reflection-like concepts that's fine, but that's a different responsibiilty.

rfcdejong replied on Friday, April 03, 2009

Just one difference:

Utilities.CallByName is using pure (slow) reflection
target.GetType().GetProperty(methodName)

Can u change the code under Utilities.CallByName to use (fast) dynamic member?
Thru it always calls at least once GetProperty.... and then adds it to a cache

DynamicMemberHandle handle = MethodCaller.GetCachedProperty(target.GetType(), propertyName);
return handle.DynamicMemberGet(target);

rfcdejong replied on Friday, April 03, 2009

Hmm i found the functionality already being available, i just didn't search good enough :)

public static class MethodCaller
{
      public static object CallPropertyGetter(object obj, string property)

Just not sure about the differences, is it really faster when using remoting or enterprise services.
In a localproxy scenario it'll be increasing memory usage, but it will speed up the property reading.

Copyright (c) Marimer LLC