Answers for "c# execute code from string"

C#
0

c# execute code from string

I managed to get a work around. I have resolved to Roslyn. Below is the code:

public class Globals
{
    public InsuredItem _i;
    public decimal SumAssured;
}

foreach (InsuredItem _i in p.InsuredItems)
{
string formula = "(_i.PremiumRate/100)*SumAssured";
var script = CSharpScript.Create<decimal>(formula, globalsType: typeof(Globals))
    .CreateDelegate();
    _i.Premium = await script(new Globals { _i = _i, SumAssured = SumAssured });
}
Posted by: Guest on March-05-2021

C# Answers by Framework

Browse Popular Code Answers by Language