I am trying to dynamically execute code on the fly. The code will be in a file but for this example i've added it as a variable (code). I been trying to CSharpScript but all examples i've seen online are just evaluating expressions.
i would like to
-Execute the RunThisMethod with the interface paramter
-if it's possible to only instantiate the MyClass once and reuse it by calling RunThisMethod with different parameters
public interface ITextColumns
{
int LineIndex { get; set; }
string[] Columns { get; set; }
}
public class TextColumns : ITextColumns
{
int ITextColumns.LineIndex { get; set; }
string[] ITextColumns.Columns { get; set; }
}
class Program
{
static void Main(string[] args)
{
var code = @"using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
public class MyClass
{
public XElement RunThisMethod(IEnumerable<ITextColumns> textColumns)
{
var result = new XElement(""Root"");
RecursiveMethod(result, textColumns);
return result;
}
private void RecursiveMethod(XElement xElement, IEnumerable<ITextColumns> textColumns)
{
//some logic to tranform textColumns to xElement
// will use linq
}
}";
var parameterToPass = Enumerable.Empty<ITextColumns>();
//Execute the code here
}
}