Monday 18 June 2018

Create and run c# code dynamically

Developing and running c# code dynamically is not that hard by using Roslyn Scripting API, you can write any type of c# code i.e. you can write a class within a string and can run it with Roslyn very easily. The below sample will help you in understanding what I mean actually.

await CSharpScript.EvaluateAsync("System.Math.Round(1.5)");

Output of the above code is:

2

You can also create classes, define their methods to perform any functionality and can use it like the above mentioned way very easily. All you need to do if to add a reference to Roslyn Scripting API which is provided in the above link and that's it.

No comments:

Post a Comment