Beispiel #1
0
        public Expression VisitRuleExpression(RuleExpressionModel m)
        {
            List <Expression> arguments = new List <Expression>()
            {
                this._context
            };

            BuildArguments(m, arguments);

            var catchBlk = new SourceCode()
            {
            };
            var p1 = catchBlk.AddVar(typeof(Exception));

            this._block.Try
            (
                new SourceCode()
                .Assign(this._resultVariable, m.Reference.Method.Call(arguments.ToArray()))
                .Add(GetCallLogAction(m.Reference.Method, m.Key, arguments.ToArray())),

                new CatchStatement()
            {
                Parameter = p1,
                Body      = catchBlk
                            .Add(GetCallLogActionException(m.Reference.Method, m.Key, p1, arguments.ToArray()))
                            .ReThrow()
            }

            );

            return(this._resultVariable);
        }
Beispiel #2
0
        private void BuildArguments(RuleExpressionModel m, List <Expression> arguments)
        {
            var parameterMethodList = m.Reference.Method.GetParameters().Skip(1).ToArray();

            for (int i = 0; i < parameterMethodList.Length; i++)
            {
                var item = parameterMethodList[i];
                if (!m.Arguments.TryGetValue(item.Name, out string value))
                {
                    throw new Exceptions.MissingArgumentNameMethodReferenceException($"missing argument {item.Name} in {m.Reference.Method.Name}");
                }

                ConstantExpression constant = GetConstants(item.Name, value, item.ParameterType);
                if (constant != null)
                {
                    arguments.Add(constant);
                }

                else
                {
                    BuildGetAccessorToArgumentGenerateCode(value.Substring(1));
                    arguments.Add(_block.LastVariable.ConvertIfDifferent(item.ParameterType));
                }
            }
        }