Пример #1
0
        public static void Main(string[] args)
        {
            var test       = ReflectionGetter.GetFields(typeof(TestClass));
            var properties = ReflectionGetter.GetProperties(typeof(TestClass));

            var temp = new TestClass()
            {
                Test1 = "Test1String",
                Test2 = 2,
                Test3 = 2.5,
                Test4 = "Test4String"
            };

            var testList = ReflectionConvert.SerializeToDictionary <TestClass>(temp);


            /*
             * var methods = ReflectionGetter.GetMethods(typeof(TestClass));
             *
             * foreach(var val in test)
             * {
             *  Console.WriteLine(val.Name + ":" + val.Type.Name + ":" + val.ReflectedType.Name);
             * }
             *
             * foreach (var val in properties)
             * {
             *  Console.WriteLine(val.Name + ":" + val.Type.Name + ":" + val.ReflectedType.Name);
             * }*/


            Console.ReadLine();
        }
        public void TestSerializeIntoDictionary()
        {
            var memberList = ReflectionConvert.SerializeToDictionary <TestClass>(testClass);

            Assert.AreEqual("Test1String", memberList["Test1"].Value);
            Assert.AreEqual(2, memberList["Test2"].Value);
            Assert.AreEqual(2.5, memberList["Test3"].Value);
            Assert.AreEqual("Test4String", memberList["Test4"].Value);
        }
        public void TestSerializeIntoList()
        {
            var memberList = ReflectionConvert.SerializeToList <TestClass>(testClass);

            Assert.IsTrue(memberList.Contains(new Property()
            {
                Name = "Test1", Type = typeof(string), ReflectedType = typeof(TestClass), Value = "Test1String"
            }));
            Assert.IsTrue(memberList.Contains(new Property()
            {
                Name = "Test2", Type = typeof(int), ReflectedType = typeof(TestClass), Value = 2
            }));
            Assert.IsTrue(memberList.Contains(new Field()
            {
                Name = "Test4", Type = typeof(string), ReflectedType = typeof(TestClass), Value = "Test4String"
            }));
            Assert.IsTrue(memberList.Contains(new Field()
            {
                Name = "Test3", Type = typeof(double), ReflectedType = typeof(TestClass), Value = 2.5
            }));
        }