Esempio n. 1
0
        public DebugExpressionVistor(SymbolDocumentInfo symbolDocumentInfo, Expression initialExpression, IExpressionDescriber expressionDescriber)
        {
            _symbolDocumentInfo  = symbolDocumentInfo;
            _expressionDescriber = expressionDescriber;

            _initialDebugView = _expressionDescriber.Describe(initialExpression);
        }
        public TDelegate Compile <TDelegate>(Expression <TDelegate> expression)
        {
            var dynamicType   = GetDynamicTypeBuilder();
            var dynamicMethod = dynamicType.DefineMethod(expression.Name, MethodAttributes.Public | MethodAttributes.Static);

            var tempFileName = Path.GetTempFileName();

            File.AppendAllText(tempFileName, _expressionDescriber.Describe(expression));

            var symbolDocument = Expression.SymbolDocument(tempFileName);

            var finalExpression = MutateLambdaExpression(expression, symbolDocument);

            CompileToMethod(finalExpression, dynamicMethod);

            var newType = dynamicType.CreateType();

            return((TDelegate)(object)Delegate.CreateDelegate(typeof(TDelegate), newType.GetMethod(dynamicMethod.Name)));
        }