Exemple #1
0
        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();

            assembly.AddFile(path1);
            assembly.AddFile(path2);


            var result = assembly.Compile();

            Assert.NotNull(result);


            var type = assembly.GetType("aaa.TestFileModel");

            Assert.NotNull(type);
            Assert.Equal("TestFileModel", type.Name);


            var @delegate = NDelegate.Random().Func <string>("return new TestFileModel().Name;", result);

            Assert.Equal("aaa", @delegate());
        }
Exemple #2
0
        public static void RunClassName4()
        {
            //ScriptCompiler.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.Compile();
            Type type = oop.GetType("HelloWorld.Test");

            Assert.Equal("Test", type.Name);
        }