コード例 #1
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="handlers">TBD</param>
        /// <param name="capturedArguments">TBD</param>
        /// <param name="signature">TBD</param>
        /// <param name="typeBuilder">TBD</param>
        /// <param name="methodName">TBD</param>
        /// <param name="methodAttributes">TBD</param>
        /// <returns>TBD</returns>
        public void CompileToMethod(IReadOnlyList <TypeHandler> handlers, IReadOnlyList <Argument> capturedArguments, MatchBuilderSignature signature, TypeBuilder typeBuilder, string methodName, MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.Static)
        {
            var result           = _expressionBuilder.BuildLambdaExpression(handlers);
            var lambdaExpression = result.LambdaExpression;
            var parameterTypes   = lambdaExpression.Parameters.Select(p => p.Type).ToArray();
            var method           = typeBuilder.DefineMethod(methodName, methodAttributes, typeof(bool), parameterTypes);

            _expressionCompiler.CompileToMethod(lambdaExpression, method);
        }
コード例 #2
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="handlers">TBD</param>
        /// <param name="capturedArguments">TBD</param>
        /// <param name="signature">TBD</param>
        /// <returns>TBD</returns>
        public PartialAction <T> Compile(IReadOnlyList <TypeHandler> handlers, IReadOnlyList <Argument> capturedArguments, MatchBuilderSignature signature)
        {
            object[] delegateArguments = null;
            var      compiledDelegate  = _cache.GetOrAdd(signature, _ => CompileToDelegate(handlers, capturedArguments, out delegateArguments));

            //If we got a cached version of the delegate we need to restructure the captured arguments suitable for the delegate
            if (delegateArguments == null)
            {
                delegateArguments = _expressionBuilder.CreateArgumentValuesArray(capturedArguments);
            }

            var partialAction = _actionBuilder.Build <T>(new CompiledMatchHandlerWithArguments(compiledDelegate, delegateArguments));

            return(partialAction);
        }