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, object[], object> GetMethodInvoker( MethodInfo methodInfo) { Func <object, object[], object> func; var lockSlim = nonVoidMethodLockSlim; var dictionary = nonVoidMethodDictionary; lockSlim.EnterUpgradeableReadLock(); try { if (!dictionary.TryGetValue(methodInfo, out func)) { lockSlim.EnterWriteLock(); try { if (!dictionary.TryGetValue(methodInfo, out func)) { func = ReflectionCompiler.CreateMethodFunc(methodInfo); dictionary[methodInfo] = func; } } finally { lockSlim.ExitWriteLock(); } } } finally { lockSlim.ExitUpgradeableReadLock(); } return(func); }
public Func <object, object[], TReturn> GetMethodInvoker <TReturn>( MethodInfo methodInfo) { object func; var lockSlim = nonVoidMethodGenericLockSlim; var dictionary = nonVoidMethodGenericDictionary; lockSlim.EnterUpgradeableReadLock(); try { if (!dictionary.TryGetValue(methodInfo, out func)) { lockSlim.EnterWriteLock(); try { if (!dictionary.TryGetValue(methodInfo, out func)) { var result = ReflectionCompiler.CreateMethodFunc <TReturn>(methodInfo); dictionary[methodInfo] = result; return(result); } } finally { lockSlim.ExitWriteLock(); } } } finally { lockSlim.ExitUpgradeableReadLock(); } return((Func <object, object[], TReturn>)func); }
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); }