public void Test1() { string path1 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "File", "TextFile1.txt"); string path2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "File", "TestFileModel.cs"); NAssembly assembly = new NAssembly("AsmTestFile"); assembly.AddFile(path1); assembly.AddFile(path2); var result = assembly.Complier(); Assert.NotNull(result); var type = assembly.GetType("TestFileModel"); Assert.NotNull(type); Assert.Equal("TestFileModel", type.Name); var @delegate = NDomain.Random().Func <string>("return new TestFileModel().Name;", result); Assert.Equal("aaa", @delegate()); }
public static void RunClassName4() { //ScriptComplier.Init(); string text = @" namespace HelloWorld {public class Test{public Test(){ Name=""111""; }public string Name; public int Age{get;set;} } }"; //根据脚本创建动态类 var oop = new NAssembly(); oop.AddScript(text); oop.Complier(); Type type = oop.GetType("Test"); Assert.Equal("Test", type.Name); }