public void DNDASDCompile() { using (DomainManagement.Random().CreateScope()) { Assert.NotEqual("Default", DomainManagement.CurrentDomain.Name); AssemblyCSharpBuilder builder = new(); builder.AssemblyName = "ASDASD1"; builder.Add("namespace TestA{ public class A { public string Name = \"Hello\"; }}"); var assemblyA = builder.GetAssembly(); Assert.NotNull(assemblyA); Assert.True(builder.Domain.UsingRecorder.HasUsing("TestA")); builder.SyntaxTrees.Clear(); builder.AssemblyName = "ASDASD2"; builder.Add(builder.Domain.UsingRecorder.ToString() + "namespace TestB{public class B { public B(){ Name=\" World!\"; } public string Name; }}"); var assemblyB = builder.GetAssembly(); Assert.True(builder.Domain.UsingRecorder.HasUsing("TestB")); Assert.NotNull(assemblyB); builder.SyntaxTrees.Clear(); builder.AssemblyName = "ASDASD3"; builder.Add(builder.Domain.UsingRecorder.ToString() + "public class C { public static string Show(){ return ((new A()).Name+(new B()).Name); } }"); var assemblyC = builder.GetAssembly(); var type = assemblyC.GetTypes().Where(item => item.Name == "C").First(); var methodInfo = type.GetMethod("Show"); var result = (string)methodInfo !.Invoke(null, null) !; Assert.Equal("Hello World!", result); } }
/// <summary> /// 使用随机域来初始化编译单元. /// </summary> /// <inheritdoc cref="CreateDomain" path="//*[not(self::summary)]"/> public static T RandomDomain(Action <AssemblyCSharpBuilder>?option = default) { return(UseDomain(DomainManagement.Random(), option)); }