private static MethodInfoCache GetMethodInfoCache(MethodInfo methodInfo) { // null check if (methodInfo == null) { throw new ArgumentNullException("methodInfo"); } // for thread safe var cacheArray = _methodInfoCacheArray; // get cache by index var cacheIndex = ObjectHeaderAccessor.GetIndex(methodInfo); if (cacheIndex > 0 && cacheIndex < cacheArray.Length) { var cached = cacheArray[cacheIndex]; if (cached != null) { // cache array may replaced by other thread, // it so we need create the cache entry again return(cached); } } // get a new cache index if (cacheIndex == 0) { if (_methodInfoCacheIndex > ObjectHeaderAccessor.MaxIndex) { return(null); } cacheIndex = Interlocked.Increment(ref _methodInfoCacheIndex); if (cacheIndex > ObjectHeaderAccessor.MaxIndex) { return(null); } } // create new cache array if size not enough if (cacheIndex >= cacheArray.Length) { var newCacheArray = new MethodInfoCache[ Math.Min( Math.Max(cacheArray.Length * 2, cacheIndex + 1), ObjectHeaderAccessor.MaxIndex + 1)]; Array.Copy(cacheArray, newCacheArray, cacheArray.Length); cacheArray = newCacheArray; _methodInfoCacheArray = newCacheArray; } // create cache entry var cache = new MethodInfoCache(methodInfo); cacheArray[cacheIndex] = cache; ObjectHeaderAccessor.SetIndex(methodInfo, cacheIndex); return(cache); }
public static void InvokeMethodOptional(object instance, string methodName, object parameter) { MethodInfo info = MethodInfoCache.GetMethodInfo(instance.GetType(), methodName, parameter.GetType()); if (info == null) { // we don't care if state does not consume events // they are persisted anyway return; } try { info.Invoke(instance, new[] { parameter }); } catch (TargetInvocationException ex) { //if (null != InternalPreserveStackTraceMethod) // InternalPreserveStackTraceMethod.Invoke(ex.InnerException, new object[0]); throw ex.InnerException; } }
public static MethodInfo FindMethod(this Type type, string name, params Type[] arguments) { return(MethodInfoCache.ForType(type).FindMethod(name, arguments)); }
static DispatchMethodFinder() { methodInfoCache = new MethodInfoCache(); }
public static MethodInfo Method(this Type type, string name, Type[] genericArguments, Type[] arguments) { return(MethodInfoCache.ForType(type).GetGeneric(name, genericArguments, arguments)); }
public static MethodInfo Method(this Type type, string name, int genericArgCount, params Type[] arguments) { return(MethodInfoCache.ForType(type).GetSubstituted(name, genericArgCount, arguments)); }
public static MethodInfo Method(this Type type, string name) { return(MethodInfoCache.ForType(type).First(name)); }
public static MethodInfo[] Methods(this Type type, string name) { return(MethodInfoCache.ForType(type).Get(name)); }
public static MethodInfo[] Methods(this Type type) { return(MethodInfoCache.ForType(type).Methods); }