Beispiel #1
0
        public static void TestMemoery()
        {
            Console.WriteLine("Memory1");
            List <Type> list    = new List <Type>();
            var         domain1 = DomainManagment.Create("TempDomain1");

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

                .Ctor(builder => builder
                      .MemberAccess(AccessTypes.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());
            }
            DomainManagment.Get("TempDomain1").Dispose();
        }
Beispiel #2
0
        public static void TestMemoery2()
        {
            Console.WriteLine("Memory2");
            var domain1 = DomainManagment.Create("TempDomain2");

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

                .Ctor(builder => builder
                      .MemberAccess(AccessTypes.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();
            }
            DomainManagment.Get("TempDomain2").Dispose();
            DomainManagment.Get("TempDomain2").Unload();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            DomainManagement.RegisterDefault <AssemblyDomain>();
            //var @operator = FastMethodOperator.DefaultDomain();
            //var actionDelegate = @operator
            //    .Param(typeof(string), "parameter")
            //    .Body("Console.WriteLine(parameter);")
            //    .Compile();

            //actionDelegate.DynamicInvoke("HelloWorld!");
            //var action = (Action<string>)actionDelegate;
            //action("HelloWorld!");
            //actionDelegate.DisposeDomain();

            //起个类
            NClass nClass = NClass.DefaultDomain();

            nClass
            .Namespace("MyNamespace")
            .Public()
            .Name("MyClass")
            .Ctor(ctor => ctor.Public().Body("MyField=\"Hello\";"))
            .Property(prop => prop
                      .Type(typeof(string))
                      .Name("MyProperty")
                      .Public()
                      .OnlyGetter("return \"World!\";")
                      );


            //添加方法
            MethodBuilder mb = new MethodBuilder();

            mb
            .Public()
            .Override()
            .Name("ToString")
            .Body("return MyField+\" \"+MyProperty;")
            .Return(typeof(string));
            nClass.Method(mb);


            //添加字段
            FieldBuilder fb = nClass.GetFieldBuilder();

            fb.Public()
            .Name("MyField")
            .Type <string>();


            //动态调用动态创建的类
            var action = NDelegate
                         .RandomDomain()
                         .Action("Console.WriteLine((new MyClass()).ToString());", nClass.GetType());

            action();
            action.DisposeDomain();
            //Console.WriteLine(typeof(List<int>[]).GetRuntimeName());
            //Console.WriteLine(typeof(List<int>[,]).GetRuntimeName());
            //Console.WriteLine(typeof(int[,]).GetRuntimeName());
            //Console.WriteLine(typeof(int[][]).GetRuntimeName());
            //Console.WriteLine(typeof(int[][,,,]).GetRuntimeName());
            Console.ReadKey();
        }