Beispiel #1
0
        public TestCaller()
        {
            string temp = "Hello";

            Dict = new Dictionary <string, Action <CallModel, object> >();
            Type type = typeof(CallModel);

            CallerManagement.AddType(type);
            DictHandler      = DictOperator.CreateFromType(type);
            FuzzyDictHandler = FuzzyDictOperator.CreateFromType(type);
            HashDictHandler  = HashDictOperator.CreateFromType(type);
            LinkHandler      = LinkOperator.CreateFromType(type);
            FuzzyLinkHandler = FuzzyLinkOperator.CreateFromType(type);
            HashLinkHandler  = HashLinkOperator.CreateFromType(type);
            Model            = new CallModel();
            Dynamic          = new CallModel();
            DictModel        = new CallModel();
            DictHandler.New();
            FuzzyDictHandler.New();
            HashDictHandler.New();
            LinkHandler.New();
            FuzzyLinkHandler.New();
            HashLinkHandler.New();
            Dict["Name"] = NDelegate.DefaultDomain().Action <CallModel, object>("arg1.Name=(string)arg2;");
        }
Beispiel #2
0
        public void TestCall3()
        {
            //创建动态类实例代理
            CallerManagement.AddType(typeof(FakeStaticTestModel2));
            var instance = DictOperator.CreateFromType(typeof(FakeStaticTestModel2));

            FakeStaticTestModel2.Name = "111";
            Assert.Equal("111", (string)instance["Name"]);
            instance["Name"] = "222";
            Assert.Equal("222", (string)instance["Name"]);
            FakeStaticTestModel2.Age = 1001;
            Assert.Equal(1001, (int)instance["Age"]);
            FakeStaticTestModel2.Temp = DateTime.Now;
            instance["Temp"]          = FakeStaticTestModel2.Temp;
            Assert.Equal(FakeStaticTestModel2.Temp, (DateTime)instance["Temp"]);
        }
Beispiel #3
0
        public void TestCall4()
        {
            //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;}
    }
}";
            //根据脚本创建动态类

            var oop = new AssemblyCSharpBuilder();

            oop.Syntax.Add(text);
            Type type = oop.GetTypeFromShortName("Test");

            CallerManagement.AddType(type);
            //创建动态类实例代理
            var instance = DictOperator.CreateFromType(type);

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

            Assert.Equal("222", (string)instance["Name"]);
        }
Beispiel #4
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.CreateFromType(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);

                var dict = DictOperator.CreateFromType(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();
        }