コード例 #1
0
        public void ItShouldPossibleToInvokeStringCompare()
        {
            const string expected =
                @"public System.Int32 Call(System.String par1, System.String par2)
{
  System.Int32 result;
  result = System.String.Compare(par1, par2, CurrentCulture);
  return result;
}";

            var newExpression = Function.Create()
                                .WithParameter <string>("par1")
                                .WithParameter <string>("par2")
                                .WithBody(
                CodeLine.CreateVariable <int>("result"),
                CodeLine.Assign(Operation.Variable("result"), StringOperation.Compare("par1", "par2"))
                )
                                .Returns("result");

            AssertString.AreEqual(expected, newExpression.ToString());

            var lambda = newExpression.ToLambda <Func <string, string, int> >();

            Assert.IsNotNull(lambda);
            var result = lambda("a", "a");

            Assert.AreEqual(0, result);
            result = lambda("a", "b");
            Assert.AreEqual(-1, result);
        }