예제 #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;");
        }
예제 #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"]);
        }
예제 #3
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>());
        }
예제 #4
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>());
        }
예제 #5
0
        public void TestCall1()
        {
            //ScriptComplier.Init();
            string text = @"using System;
using System.Collections;
using System.Linq;
using System.Text;
 
namespace HelloWorld
{
    public static class StaticTest2
    {
        static StaticTest2(){
            Name=""111"";
        }

        public static string Name;
        public static int Age{get;set;}
    }
}";
            //根据脚本创建动态类
            var oop = new AssemblyCSharpBuilder();

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

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

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

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