I’ve read that i should create and reuse delegates to get the value of a property of an object.
I use this code to create the Delegate
var objParm = Expression.Parameter(property.DeclaringType, "o");
Type delegateType = typeof(Func<,>).MakeGenericType(property.DeclaringType, property.PropertyType);
var lambda = Expression.Lambda(delegateType, Expression.Property(objParm, property.Name), objParm);
return lambda.Compile()
Now i only find the way to use the delegate in the call of “DynamicInvoke”.
Now i want to change the call to “invoke” cause of performance reasons.
I tried
Delegate.Method.Invoke(invokedObject, null);
But after the call i get the exception
MethodInfo must be a RuntimeMethodInfo.
I have an cache class for each property where i can store the dynamically created delegate.
What should i do so i am able to use “normal” Invokes?
Thanks a lot.
I’ve created a class that I use when I need to access properties by using their name as text. The class caches all properties for an class.
Usage:
The class