Пример #1
0
        public override bool Equals(object obj)
        {
            if (object.ReferenceEquals(this, obj))
            {
                return(true);
            }

            CompiledExpressionCacheEntry objAsEntry = obj as CompiledExpressionCacheEntry;

            return(objAsEntry != null && _expressionEqualityComparer.Equals(this.Expression, objAsEntry.Expression));
        }
Пример #2
0
        public static T CachedCompile <T>(this Expression <T> expression)
            where T : class
        {
            var closureTransformer = new ClosedToOpenExpressionTransformer(expression);

            CompiledExpressionCacheEntry entry = new CompiledExpressionCacheEntry(closureTransformer.OpenVersion);

            Delegate compiledExpression;

            if (!_cache.TryGetValue(entry, out compiledExpression))
            {
                compiledExpression = closureTransformer.OpenVersion.Compile() as Delegate;
                _cache[entry]      = compiledExpression;
            }

            if (!closureTransformer.WasAlreadyOpen)
            {
                return(ClosedToOpenExpressionFactory.CreateMetaClosure <T>(compiledExpression, closureTransformer.Constants));
            }
            else
            {
                return(compiledExpression as T);
            }
        }