Example #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 TestGetProperties()
        {
            var fieldList = ReflectionGetter.GetProperties(typeof(TestClass));

            Assert.IsTrue(fieldList.Contains(new Property()
            {
                Name = "Test1", Type = typeof(string), ReflectedType = typeof(TestClass), Value = "-1"
            }));
            Assert.IsTrue(fieldList.Contains(new Property()
            {
                Name = "Test2", Type = typeof(int), ReflectedType = typeof(TestClass), Value = -1
            }));
        }
        public void TestGetFields()
        {
            var fieldList = ReflectionGetter.GetFields(typeof(TestClass));

            Assert.IsTrue(fieldList.Contains(new Field()
            {
                Name = "Test4", Type = typeof(string), ReflectedType = typeof(TestClass), Value = "-1"
            }));
            Assert.IsTrue(fieldList.Contains(new Field()
            {
                Name = "Test3", Type = typeof(double), ReflectedType = typeof(TestClass), Value = -1.0
            }));
        }
        public void TestGetVariableMember()
        {
            var variableList = ReflectionGetter.GetVariableMembers(typeof(TestClass));

            Assert.IsTrue(variableList.Contains(new Property()
            {
                Name = "Test1", Type = typeof(string), ReflectedType = typeof(TestClass), Value = "-1"
            }));
            Assert.IsTrue(variableList.Contains(new Property()
            {
                Name = "Test2", Type = typeof(int), ReflectedType = typeof(TestClass), Value = -1
            }));
            Assert.IsTrue(variableList.Contains(new Field()
            {
                Name = "Test4", Type = typeof(string), ReflectedType = typeof(TestClass), Value = -1.0
            }));
            Assert.IsTrue(variableList.Contains(new Field()
            {
                Name = "Test3", Type = typeof(double), ReflectedType = typeof(TestClass), Value = "-1"
            }));
        }