Quantcast
Channel: Cinchoo » String
Viewing all articles
Browse latest Browse all 10

Cinchoo – String.Evaluate(), Part 2

$
0
0

Using system library routines

In some cases, you may want to use system library routines while evaluating expression. Library routines are specified with ~ delimiter. When specifying library routine, please give full namespace type name.

Please see the sample below

1. Add reference to Cinchoo.Core.dll assembly

2. Namespace System

Sample:

static void Main(string[] args)
{
    try
    {
        object x1 = "{~System.DateTime.Now.Ticks~ * 10}".Evaluate();
        Console.WriteLine("Output of {~System.DateTime.Now.Ticks~ * 10}: " + x1 + ", ObjectType:" + x1.GetType());

        object x2 = "{2 + ~System.Math.Sin(10)~ * 10}".Evaluate();
        Console.WriteLine("Output of {2 + ~Math.Sin(10)~ * 10}: " + x2 + ", ObjectType:" + x2.GetType());
    }
    finally
    {
        ChoAppDomain.Exit();
    }
}

When you run the above code, the output will be

Output of {~System.DateTime.Now.Ticks~ * 10}: 6346500617481320790, ObjectType: System.Int64
Output of {2 + ~Math.Sin(10)~ * 10}: -3.4402111088937, ObjectType: System.Double

Press any key to continue . . .

Happy coding!!!




Viewing all articles
Browse latest Browse all 10

Trending Articles