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);
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
 public static MethodInfo FindMethod(this Type type, string name, params Type[] arguments)
 {
     return(MethodInfoCache.ForType(type).FindMethod(name, arguments));
 }
Ejemplo n.º 4
0
 static DispatchMethodFinder()
 {
     methodInfoCache = new MethodInfoCache();
 }
Ejemplo n.º 5
0
 public static MethodInfo Method(this Type type, string name, Type[] genericArguments, Type[] arguments)
 {
     return(MethodInfoCache.ForType(type).GetGeneric(name, genericArguments, arguments));
 }
Ejemplo n.º 6
0
 public static MethodInfo Method(this Type type, string name, int genericArgCount, params Type[] arguments)
 {
     return(MethodInfoCache.ForType(type).GetSubstituted(name, genericArgCount, arguments));
 }
Ejemplo n.º 7
0
 public static MethodInfo Method(this Type type, string name)
 {
     return(MethodInfoCache.ForType(type).First(name));
 }
Ejemplo n.º 8
0
 public static MethodInfo[] Methods(this Type type, string name)
 {
     return(MethodInfoCache.ForType(type).Get(name));
 }
Ejemplo n.º 9
0
 public static MethodInfo[] Methods(this Type type)
 {
     return(MethodInfoCache.ForType(type).Methods);
 }