Esempio n. 1
0
        public void TestCall3()
        {
            //创建动态类实例代理
            var instance = LinkOperator <TestB> .Create();

            instance.New();
            Assert.Equal("111", instance["Name"].Get <string>());

            //调用动态委托赋值
            instance.Set("Name", "222");

            Assert.Equal("222", instance["Name"].Get <string>());


            var c = instance["InstanceC"].Get <TestC>();

            Assert.Equal("abc", c.Name);


            instance["InstanceC"].Set(new TestC()
            {
                Name = "bbca"
            });
            Assert.Equal("bbca", instance["InstanceC"].Get <TestC>().Name);
        }
Esempio n. 2
0
        public void TestCall1()
        {
            //ScriptComplier.Init();
            string text = @"using System;
using System.Collections;
using System.Linq;
using System.Text;
 
namespace HelloWorld
{
    public class Test
    {
        public Test(){
            Name=""111"";
        }

        public string Name;
        public int Age{get;set;}
    }
}";
            //根据脚本创建动态类
            Type type = (new OopComplier()).GetClassType(text);
            //创建动态类实例代理
            var instance = LinkOperator.Create(type);

            instance.New();
            //Get动态调用
            Assert.Equal("111", instance["Name"].Get <string>());
            //调用动态委托赋值
            instance.Set("Name", "222");

            Assert.Equal("222", instance["Name"].Get <string>());
        }
Esempio n. 3
0
        public void TestCall2()
        {
            //创建动态类实例代理
            var instance = LinkOperator <TestB> .Create();

            instance.New();
            Assert.Equal("111", instance["Name"].Get <string>());

            //调用动态委托赋值
            instance.Set("Name", "222");

            Assert.Equal("222", instance["Name"].Get <string>());
        }
Esempio n. 4
0
        public void TestCall3()
        {
            //创建动态类实例代理
            var instance = LinkOperator.Create(typeof(FakeStaticTestModel1));

            FakeStaticTestModel1.Name = "111";
            Assert.Equal("111", instance["Name"].Get <string>());
            instance["Name"].Set("222");
            Assert.Equal("222", instance["Name"].Get <string>());
            FakeStaticTestModel1.Age = 1001;
            Assert.Equal(1001, instance.Get <int>("Age"));
            FakeStaticTestModel1.Temp = DateTime.Now;
            instance["Temp"].Set(FakeStaticTestModel1.Temp);
            Assert.Equal(FakeStaticTestModel1.Temp, instance["Temp"].Get <DateTime>());
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            TempTime = DateTime.Now;
            Stopwatch stopwatch = new Stopwatch();

            for (int j = 0; j < 20; j++)
            {
                Console.WriteLine("=========================================");


                stopwatch.Restart();
                for (int i = 0; i < 40000; i++)
                {
                    var tEntity = new TestB();
                    if (tEntity.A2ge712 == "111")
                    {
                        //调用动态委托赋值
                        tEntity.A2ge712 = "222";
                    }
                }
                stopwatch.Stop();
                Console.WriteLine("原生调用:\t\t" + stopwatch.Elapsed);



                var entity = LinkOperator.Create(typeof(TestB));
                stopwatch.Restart();
                for (int i = 0; i < 40000; i++)
                {
                    entity.New();
                    if (entity.Get <string>("A2ge712") == "111")
                    {
                        //调用动态委托赋值
                        entity.Set("A2ge712", "222");
                    }
                }
                stopwatch.Stop();
                Console.WriteLine("NCaller SimpleCaller:\t" + stopwatch.Elapsed);


                stopwatch.Restart();
                for (int i = 0; i < 40000; i++)
                {
                    RunDynamic(new TestB());
                }
                stopwatch.Stop();
                Console.WriteLine("Dynamic :\t\t" + stopwatch.Elapsed);


                var dict = DictOperator.Create(typeof(TestB));
                stopwatch.Restart();
                for (int i = 0; i < 40000; i++)
                {
                    dict.New();
                    if ((string)(dict["A2ge712"]) == "111")
                    {
                        //调用动态委托赋值
                        dict["A2ge712"] = "222";
                    }
                }
                stopwatch.Stop();
                Console.WriteLine("NCaller DictCaller:\t" + stopwatch.Elapsed);

                stopwatch.Restart();
                for (int i = 0; i < 40000; i++)
                {
                    RunDynamic(new TestB());
                }
                stopwatch.Stop();
                Console.WriteLine("Dynamic :\t\t" + stopwatch.Elapsed);


                stopwatch.Restart();
                for (int i = 0; i < 40000; i++)
                {
                    var tEntity = (new TestB()).LinkCaller();
                    if (tEntity.Get <string>("A2ge712") == "111")
                    {
                        //调用动态委托赋值
                        tEntity.Set("A2ge712", "222");
                    }
                }
                stopwatch.Stop();
                Console.WriteLine("NCaller Extension:\t" + stopwatch.Elapsed);


                //entity = DynamicCaller.Create(typeof(TestB));
                //stopwatch.Restart();
                //for (int i = 0; i < 40000; i++)
                //{
                //    entity.New();
                //    if (entity.Get<DateTime>("Time") != TempTime)
                //    {
                //        //调用动态委托赋值
                //        entity.Set("Time", TempTime);
                //    }
                //}
                //stopwatch.Stop();
                //Console.WriteLine("NCaller SimpleCaller:\t" + stopwatch.Elapsed);

                //stopwatch.Restart();
                //for (int i = 0; i < 40000; i++)
                //{
                //    RunDynamicTime(new TestB());
                //}
                //stopwatch.Stop();
                //Console.WriteLine("Dynamic :\t\t" + stopwatch.Elapsed);

                //entity = DynamicCaller.Create(typeof(TestB));
                //stopwatch.Restart();
                //for (int i = 0; i < 40000; i++)
                //{
                //    entity.New();
                //    if (entity.Get<DateTime>("Time") != TempTime)
                //    {
                //        //调用动态委托赋值
                //        entity.Set("Time", TempTime);
                //    }
                //}
                //stopwatch.Stop();
                //Console.WriteLine("NCaller SimpleCaller:\t" + stopwatch.Elapsed);
                Console.WriteLine("=========================================");
            }

            //var dict = DictOperator<TestB>.Create();
            //dict["Name"] = "Hello";
            //dict["Age"] = 100;
            //dict["Time"] = DateTime.Now;

            Console.ReadKey();
        }