Ejemplo n.º 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;");
        }
Ejemplo n.º 2
0
        public void TestCall2()
        {
            //创建动态类实例代理
            CallerManagement.AddType(typeof(StaticTestModel1));
            var instance = LinkOperator.CreateFromType(typeof(StaticTestModel1));

            StaticTestModel1.Name = "111";
            Assert.Equal("111", instance["Name"].Get <string>());
            instance["Name"].Set("222");
            Assert.Equal("222", instance["Name"].Get <string>());
            StaticTestModel1.Age = 1001;
            Assert.Equal(1001, instance.Get <int>("Age"));
            StaticTestModel1.Temp = DateTime.Now;
            instance["Temp"].Set(StaticTestModel1.Temp);
            Assert.Equal(StaticTestModel1.Temp, instance["Temp"].Get <DateTime>());
        }
Ejemplo n.º 3
0
        public void TestCall1()
        {
            //ScriptComplier.Init();
            string text = @"using System;
using System.Collections;
using System.Linq;
using System.Text;
 
namespace HelloWorld
{
    public class Test2
    {
        public Test2(){
            Name=""111"";
        }

        public string Name;
        public int Age{get;set;}
    }
}";

            //根据脚本创建动态类
            var oop = new AssemblyCSharpBuilder();

            oop.Syntax.Add(text);
            var type = oop.GetTypeFromShortName("Test2");

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

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

            Assert.Equal("222", instance["Name"].Get <string>());
        }
Ejemplo n.º 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();
        }