Exemple #1
0
        public static void TestMemoery2()
        {
            Console.WriteLine("Memory2");
            var domain1 = DomainManagement.Create("TempDomain2");

            for (int i = 0; i < 10; i += 1)
            {
                Thread.Sleep(5000);
                Console.WriteLine("new");
                NClass nStruct = new NClass();
                nStruct
                .Namespace("Core30")
                .Name($"Test{i}")

                .Ctor(builder => builder
                      .Public()
                      .Param <string>("name")
                      .Body("Name=name;"))
                .PublicField <string>("Name")
                .PublicField <string>("Name1")
                .PublicField <string>("Name2")
                .PublicField <string>("Name3")
                .PublicField <string>("Name4");
                var type = nStruct.GetType();
            }
            DomainManagement.Get("TempDomain2").Dispose();
            DomainManagement.Get("TempDomain2").Unload();
        }
Exemple #2
0
        public static void TestMemoery()
        {
            Console.WriteLine("Memory1");
            List <Type> list    = new List <Type>();
            var         domain1 = DomainManagement.Create("TempDomain1");

            for (int i = 0; i < 500; i += 1)
            {
                Console.WriteLine("new");
                NClass nStruct = new NClass();
                nStruct
                .Namespace("Core301")
                .Name($"Test{i}")

                .Ctor(builder => builder
                      .Public()
                      .Param <string>("name")
                      .Body("Name=name;"))
                .PublicField <string>("Name")
                .PublicField <string>("Name1")
                .PublicField <string>("Name2")
                .PublicField <string>("Name3")
                .PublicField <string>("Name4");
                list.Add(nStruct.GetType());
            }
            DomainManagement.Get("TempDomain1").Dispose();
        }
Exemple #3
0
        public void DDReferenceCompile()
        {
            using (DomainManagement.Create("DiffDomainReferenceCompare1").CreateScope())
            {
                Assert.NotEqual("Default", DomainManagement.CurrentDomain.Name);
                AssemblyCSharpBuilder builder1 = new();
                builder1.Add(DefaultUsing.UsingScript + "namespace TestA{ public class A {  public string Name = \"Hello\"; public static NatashaUsingCache Get(){ return null;} }}");
                var assemblyA = builder1
                                .CompileWithReferenceLoadBehavior(LoadBehaviorEnum.UseDefault)
                                .GetAssembly();
                var typeA = assemblyA.GetTypes().Where(item => item.Name == "A").First();
                var objA  = Activator.CreateInstance(typeA);
                Assert.NotNull(assemblyA);
                Assert.True(builder1.Domain.UsingRecorder.HasUsing("TestA"));
            }
            using (DomainManagement.Create("DiffDomainReferenceCompare2").CreateScope())
            {
                AssemblyCSharpBuilder builder2 = new();
                builder2.Add(DefaultUsing.UsingScript + "namespace TestB{ public class A {  public string Name = \"Hello\";  public static NatashaUsingCache Get(){ return null;}  }}");
                var assemblyB = builder2
                                .CompileWithReferenceLoadBehavior(LoadBehaviorEnum.None)
                                .GetAssembly();
                var typeB = assemblyB.GetTypes().Where(item => item.Name == "A").First();
                var objB  = Activator.CreateInstance(typeB);
                Assert.NotNull(assemblyB);
                Assert.True(builder2.Domain.UsingRecorder.HasUsing("TestB"));
            }
            var domain1 = DomainManagement.Get("DiffDomainReferenceCompare1") !;
            var domain2 = DomainManagement.Get("DiffDomainReferenceCompare2") !;

            Assert.True(domain1.Assemblies.Any());
            Assert.Equal(domain1.Assemblies.Count(), domain2.Assemblies.Count());
            Assert.True(domain1.References.Count == domain2.References.Count);
        }
Exemple #4
0
 public static void Release()
 {
     func = null;
     for (int i = 0; i < count; i++)
     {
         var handler = DomainManagement.Get("test" + i.ToString());
         handler.Dispose();
     }
 }
Exemple #5
0
        internal string ForTest1()
        {
            var domain   = DomainManagement.Create("SingleDomainAsmTest1");
            var assembly = domain.CreateAssembly("AsmTest1");

            var @interface = assembly
                             .CreateInterface("IAsmT1")
                             .Using("System")
                             .Public()
                             .Body("string ShowMethod(string str);");


            var @class = assembly
                         .CreateClass("ClassAsm")
                         .Using("System")
                         .Public()
                         .Inheritance("IAsmT1")
                         .Method(method => method
                                 .Public()
                                 .DefinedName("ShowMethod")
                                 .Param <string>("str")
                                 .Body("return str+AsmEnum.Test.ToString();")
                                 .Return <string>()
                                 );

            var @enum = assembly
                        .CreateEnum("AsmEnum")
                        .Public()
                        .EnumField("Test")
                        .EnumField("Test1")
                        .EnumField("Test2", 1);

            var result = assembly.GetAssembly();
            var type   = assembly.GetTypeFromFullName(@class.NamespaceScript + "." + "ClassAsm");

            var builder = FastMethodOperator.DefaultDomain();

            builder.AssemblyBuilder.Compiler.Domain = domain;
            var @delegate = builder.Using(type).Body(@"
            ClassAsm obj = new ClassAsm();
            return obj.ShowMethod(""Hello"");
            ").Compile <Func <string, string> >();

            DomainManagement.Get("SingleDomainAsmTest1").Dispose();
            return(@delegate("hello"));
        }
Exemple #6
0
        public string Collection(string typeName)
        {
            for (int i = 0; i < 20; i++)
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            if (DomainManagement.IsDeleted(typeName))
            {
                return("Has Collection!");
            }
            else
            {
                var a = DomainManagement.Get(typeName);
                a.Dispose();
            }

            return("No Collection!");
        }
Exemple #7
0
        public static void Show()
        {
            //默认共享域
            NStruct nStruct = new NStruct();
            //nStruct
            //    .Namespace("Core30")
            //    .OopName("Test")
            //    .Ctor(builder => builder
            //        .PublicMember
            //        .Param<string>("name")
            //        .Body("Name=name;"))
            //    .PublicField<string>("Name");
            //var type = nStruct.GetType();



            var domain1 = DomainManagement.Create("TempDomain");

            // nStruct = new NStruct();
            // nStruct

            //     .Namespace("Core30")
            //     .OopName("Test1")
            //     .Ctor(builder => builder
            //         .PublicMember
            //         .Param<string>("name")
            //         .Body(@"Name=name+""1"";"))
            //     .PublicField<string>("Name");
            //var type1 = nStruct.GetType();
            // domain1.RemoveType(type1);

            // nStruct = new NStruct();
            // nStruct

            //     .Namespace("Core30")
            //     .OopName("Test")
            //     .Ctor(builder => builder
            //         .PublicMember
            //         .Param<string>("name")
            //         .Body(@"Name=name+""2"";"))
            //     .PublicField<string>("Name");
            // var type3 = nStruct.GetType();
            // domain1.RemoveType(type3);


            nStruct = new NStruct();
            nStruct.AssemblyBuilder.Compiler.Domain = domain1;
            nStruct

            .Namespace("Core30")
            .Name("Test")
            .Ctor(builder => builder
                  .Public()
                  .Param <string>("name")
                  .Body(@"Name=name+""3"";"))
            .PublicField <string>("Name");
            var type4 = nStruct.GetType();


            //nStruct = new NStruct();
            //nStruct
            //    .INDelegate(domain1)
            //    .Namespace("Core30")
            //    .OopName("Test")
            //    .Ctor(builder => builder
            //        .PublicMember
            //        .Param<string>("name")
            //        .Body(@"Name=name+""1"";"))
            //    .PublicField<string>("Name");
            //var type2 = nStruct.GetType();



            var temp = FastMethodOperator.DefaultDomain();

            temp.AssemblyBuilder.Compiler.Domain = domain1;
            temp
            //.Using<Test>()
            //.Using(type)
            .Using(type4)
            //.MethodAttribute<MethodImplAttribute>("MethodImplOptions.NoInlining")
            .Body(@"
Test obj = new Test(""Hello World!"");
Console.WriteLine(obj.Name);"
                  );
            action = temp.Compile <Action>();
            action();
            DomainManagement.Get("TempDomain").Dispose();
        }