コード例 #1
0
        public Delegate GetOrCreateConstructorCall(AssembledTypeID typeID, Type delegateType, bool allowNonPublic)
        {
            ArgumentUtility.DebugCheckNotNull("delegateType", delegateType);
            ArgumentUtility.DebugCheckTypeIsAssignableFrom("delegateType", delegateType, typeof(Delegate));

            var constructionKey = new ConstructionKey(typeID, delegateType, allowNonPublic);

            return(_constructorCalls.GetOrAdd(constructionKey, _createConstructorCallFunc));
        }
コード例 #2
0
ファイル: ConstructionKey.cs プロジェクト: re-motion/TypePipe
        public ConstructionKey(AssembledTypeID typeID, Type delegateType, bool allowNonPublic)
        {
            ArgumentUtility.DebugCheckNotNull("delegateType", delegateType);

            _typeID         = typeID;
            _delegateType   = delegateType;
            _allowNonPublic = allowNonPublic;

            // Pre-compute hash code.
            _hashCode = EqualityUtility.GetRotatedHashCode(_typeID.GetHashCode(), delegateType, allowNonPublic);
        }
コード例 #3
0
ファイル: TypeCache.cs プロジェクト: re-motion/TypePipe
 private Lazy <Type> CreateAssembledType(AssembledTypeID typeID)
 {
     return(new Lazy <Type> (
                () =>
     {
         var assemblyContext = _assemblyContextPool.Dequeue();
         try
         {
             var result = _typeAssembler.AssembleType(typeID, assemblyContext.ParticipantState, assemblyContext.MutableTypeBatchCodeGenerator);
             AddAdditionalTypesToCache(result.AdditionalTypes);
             return result.Type;
         }
         finally
         {
             _assemblyContextPool.Enqueue(assemblyContext);
         }
     },
                LazyThreadSafetyMode.ExecutionAndPublication));
 }
コード例 #4
0
ファイル: TypeCache.cs プロジェクト: re-motion/TypePipe
        public Type GetOrCreateType(AssembledTypeID typeID)
        {
            var lazyType = _assembledTypes.GetOrAdd(typeID, _createAssembledTypeFunc);

            try
            {
                return(lazyType.Value);
            }
            catch
            {
                // Lazy<T> with ExecutionAndPublication and a create-function caches the exception.
                // In order to renew the Lazy for another attempt, a replace of the Lazy-object is performed, but only if the _assembledTypes dictionary
                // still holds the original Lazy (that cached the exception). This avoids a race with a parallel thread that requested the same type.
                if (_assembledTypes.TryUpdate(typeID, _createAssembledTypeFunc(typeID), lazyType))
                {
                    throw;
                }

                // Can theoretically cause a StackOverflowException in case of starvation. We are ignoring this very remote possiblity.
                // This code path cannot be tested.
                return(GetOrCreateType(typeID));
            }
        }