コード例 #1
0
        static DispatchInfo GetDispatchInfo(Type targetType, Type messageType)
        {
            DispatchInfo dispatchInfo = null;

            dispatchInfoCacheLocker.EnterReadLock();
            {
                if (dispatchInfoCache.ContainsKey(targetType))
                {
                    var targetCache = dispatchInfoCache[targetType];
                    if (targetCache.ContainsKey(messageType))
                    {
                        dispatchInfo = targetCache[messageType];
                    }
                }
            }
            dispatchInfoCacheLocker.ExitReadLock();

            if (dispatchInfo != null)
            {
                return(dispatchInfo);
            }

            dispatchInfo = new DispatchInfo(messageType, targetType, FindHandleMethod(targetType, messageType));
            dispatchInfoCacheLocker.EnterWriteLock();
            {
                if (!dispatchInfoCache.ContainsKey(targetType))
                {
                    dispatchInfoCache.Add(targetType, new Dictionary <Type, DispatchInfo>());
                }
                var targetCache = dispatchInfoCache[targetType];
                if (targetCache.ContainsKey(messageType))
                {
                    targetCache.Add(messageType, dispatchInfo);
                }
            }
            dispatchInfoCacheLocker.ExitWriteLock();

            return(dispatchInfo);
        }
コード例 #2
0
        static DispatchInfo GetDispatchInfo(Type targetType, Type messageType) {
            DispatchInfo dispatchInfo = null;
            dispatchInfoCacheLocker.EnterReadLock();
            {
                if (dispatchInfoCache.ContainsKey(targetType)) {
                    var targetCache = dispatchInfoCache[targetType];
                    if (targetCache.ContainsKey(messageType)) {
                        dispatchInfo = targetCache[messageType];
                    }
                }
            }
            dispatchInfoCacheLocker.ExitReadLock();

            if (dispatchInfo != null)
                return dispatchInfo;

            dispatchInfo = new DispatchInfo(messageType, targetType, FindHandleMethod(targetType, messageType));
            dispatchInfoCacheLocker.EnterWriteLock();
            {
                if (!dispatchInfoCache.ContainsKey(targetType)) {
                    dispatchInfoCache.Add(targetType, new Dictionary<Type, DispatchInfo>());
                }
                var targetCache = dispatchInfoCache[targetType];
                if (targetCache.ContainsKey(messageType)) {
                    targetCache.Add(messageType, dispatchInfo);
                }
            }
            dispatchInfoCacheLocker.ExitWriteLock();

            return dispatchInfo;
        }