Cinchoo – String.Evaluate(), Part 2

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!!!


About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: