public Action <object, TProperty> GetPropertySetter <TProperty>( PropertyInfo propertyInfo, DelegateCreationMode creationMode) { var dictionary = setterGenericDictionary; if (!dictionary.TryGetValue(propertyInfo, out object result)) { switch (creationMode) { case DelegateCreationMode.SlowCreationFastPerformance: result = ReflectionCompiler.CreatePropertySetter <TProperty>(propertyInfo); break; default: var setMethod = propertyInfo.SetMethod; result = new Action <object, TProperty>( (owner, newValue) => setMethod.Invoke(owner, new object[] { newValue })); break; } dictionary[propertyInfo] = result; } return((Action <object, TProperty>)result); }
public Action <object, object> GetPropertySetter( PropertyInfo propertyInfo, DelegateCreationMode creationMode) { var dictionary = setterDictionary; if (!dictionary.TryGetValue(propertyInfo, out var setter)) { switch (creationMode) { case DelegateCreationMode.SlowCreationFastPerformance: setter = ReflectionCompiler.CreatePropertySetter(propertyInfo); break; default: var setMethod = propertyInfo.SetMethod; setter = (owner, newValue) => setMethod.Invoke(owner, new [] { newValue }); break; } dictionary[propertyInfo] = setter; } return(setter); }
public Func <object, object[], TReturn> GetMethodInvoker <TReturn>( MethodInfo methodInfo, DelegateCreationMode creationMode) { var dictionary = nonVoidMethodGenericDictionary; if (!dictionary.TryGetValue(methodInfo, out object result)) { switch (creationMode) { case DelegateCreationMode.SlowCreationFastPerformance: result = ReflectionCompiler.CreateMethodFunc <TReturn>(methodInfo); break; default: result = new Func <object, object[], TReturn>( (owner, args) => (TReturn)methodInfo.Invoke(owner, args)); break; } dictionary[methodInfo] = result; } return((Func <object, object[], TReturn>)result); }
public Func <object, TProperty> GetPropertyGetter <TProperty>( PropertyInfo propertyInfo, DelegateCreationMode creationMode) { Func <object, TProperty> result; var dictionary = getterDictionary; if (!dictionary.TryGetValue(propertyInfo, out object getter)) { switch (creationMode) { case DelegateCreationMode.SlowCreationFastPerformance: result = ReflectionCompiler.CreatePropertyGetter <TProperty>(propertyInfo); break; default: var getMethod = propertyInfo.GetMethod; result = owner => (TProperty)getMethod.Invoke(owner, null); break; } dictionary[propertyInfo] = result; return(result); } result = (Func <object, TProperty>)getter; return(result); }
public Func <object[], object> GetConstructorFunc( ConstructorInfo info, DelegateCreationMode creationMode) { var dictionary = constructorDictionary; if (!dictionary.TryGetValue(info, out Func <object[], object> result)) { switch (creationMode) { case DelegateCreationMode.SlowCreationFastPerformance: result = ReflectionCompiler.CreateConstructorFunc(info); break; default: result = info.Invoke; break; } dictionary[info] = result; } return(result); }
/* The Get* methods in this class are deliberately more verbose * than they need to be. We could remove the duplication within * each code block, however the code needs to be fast, * and the overhead of creating an Action for each call * would not be worth it. */ public Func <object, object> GetPropertyGetter( PropertyInfo propertyInfo, DelegateCreationMode creationMode) { var dictionary = getterGenericDictionary; if (!dictionary.TryGetValue(propertyInfo, out var getter)) { switch (creationMode) { case DelegateCreationMode.SlowCreationFastPerformance: getter = ReflectionCompiler.CreatePropertyGetter(propertyInfo); break; default: getter = propertyInfo.GetValue; break; } dictionary[propertyInfo] = getter; } return(getter); }
public Func <object, object[], object> GetMethodInvoker( MethodInfo methodInfo, DelegateCreationMode creationMode) { var dictionary = nonVoidMethodDictionary; if (!dictionary.TryGetValue(methodInfo, out var result)) { switch (creationMode) { case DelegateCreationMode.SlowCreationFastPerformance: result = ReflectionCompiler.CreateMethodFunc(methodInfo); break; default: result = methodInfo.Invoke; break; } dictionary[methodInfo] = result; } return(result); }
public Action <object, object[]> GetVoidMethodInvoker( MethodInfo methodInfo, DelegateCreationMode creationMode) { var dictionary = voidMethodDictionary; if (!dictionary.TryGetValue(methodInfo, out var result)) { switch (creationMode) { case DelegateCreationMode.SlowCreationFastPerformance: result = ReflectionCompiler.CreateMethodAction(methodInfo); break; default: result = (owner, args) => methodInfo.Invoke(owner, args); break; } dictionary[methodInfo] = result; } return(result); }