Exemple #1
0
        public unsafe void TestCall6()
        {
            //创建动态类实例代理
            var instance = PrecisionDictOperator <TestB> .Create();

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

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

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


            var c = (TestC)instance["InstanceC"];

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


            instance["InstanceC"] = (new TestC()
            {
                Name = "bbca"
            });
            Assert.Equal("bbca", ((TestC)instance["InstanceC"]).Name);
        }
Exemple #2
0
        public unsafe void TestCall5()
        {
            //创建动态类实例代理
            var instance = PrecisionDictOperator <TestB> .Create();

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

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

            Assert.Equal("222", (string)instance["Name"]);
        }
Exemple #3
0
        public static Func <DictBase> Switch <T>(AlgorithmKind kind)
        {
            switch (kind)
            {
            case AlgorithmKind.Precision:
                return(() => PrecisionDictOperator <T> .Create());

            case AlgorithmKind.Hash:
                return(() => HashDictOperator <T> .Create());

            case AlgorithmKind.Fuzzy:
                return(() => FuzzyDictOperator <T> .Create());

            default:
                throw new InvalidOperationException("Unknown AlgorithmKind.");
            }
        }
        public unsafe void GenericMetadataTest()
        {
            var instance = PrecisionDictOperator <NiceAct> .Create();

            var members0 = instance.GetMembers();
            var members1 = instance.GetCanReadMembers();
            var members2 = instance.GetCanReadMembers();

            Assert.Equal(5, members0.Count());
            Assert.Equal(5, members1.Count());
            Assert.Equal(5, members2.Count());

            Assert.NotNull(instance.GetMember("Name"));
            Assert.NotNull(instance.GetMember("Age"));
            Assert.NotNull(instance.GetMember("Birthday"));
            Assert.NotNull(instance.GetMember("Country"));
            Assert.NotNull(instance.GetMember("IsValid"));

            Assert.Equal(typeof(string), instance.GetMember("Name").MemberType);
            Assert.Equal(typeof(int), instance.GetMember("Age").MemberType);
            Assert.Equal(typeof(DateTime), instance.GetMember("Birthday").MemberType);
            Assert.Equal(typeof(Country), instance.GetMember("Country").MemberType);
            Assert.Equal(typeof(bool), instance.GetMember("IsValid").MemberType);
        }