AjScript.Tests.Language.FunctionTests.BuildFactorialFunction C# (CSharp) Method

BuildFactorialFunction() private static method

private static BuildFactorialFunction ( IContext context ) : ICallable
context IContext
return ICallable
        private static ICallable BuildFactorialFunction(IContext context)
        {
            IExpression condition = new CompareExpression(ComparisonOperator.LessEqual, new VariableExpression("n"), new ConstantExpression(1));

            ICommand return1 = new ReturnCommand(new ConstantExpression(1));
            ICommand return2 = new ReturnCommand(
                new ArithmeticBinaryExpression(
                    ArithmeticOperator.Multiply,
                    new VariableExpression("n"),
                    new InvokeExpression(new VariableExpression("Factorial"), new IExpression[] { new ArithmeticBinaryExpression(ArithmeticOperator.Subtract, new VariableExpression("n"), new ConstantExpression(1)) })));

            ICommand ifcmd = new IfCommand(condition, return1, return2);
            ICallable factorial = new Function(new string[] { "n" }, ifcmd, context);

            return factorial;
        }