コード例 #1
0
        public static void TestObjectVsTypedNewGetPropertyValue()
        {
            var test = new TestReflectionUtility();

            test.String = "XXX";

            Stopwatch timer = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                ReflectionUtility.GetPropertyValue(test, "String");
            }

            timer.Stop();
            Console.WriteLine(string.Format("Elapsed para obj: {0}", timer.Elapsed));

            timer = Stopwatch.StartNew();
            for (int i = 0; i < 1000000; i++)
            {
                ReflectionUtility.GetPropertyValue <string>(test, "String");
            }

            timer.Stop();
            Console.WriteLine(string.Format("Elapsed para T: {0}", timer.Elapsed));
        }
コード例 #2
0
        public void TestGetPropertyValue()
        {
            var test = new TestReflectionUtility();

            test.String  = "XXX";
            test.Int     = 999;
            test.Long    = 999;
            test.Decimal = Decimal.Parse("999,5");
            test.Date    = new DateTime(1972, 12, 5);
            test.Bool    = true;

            Assert.AreEqual("XXX", ReflectionUtility.GetPropertyValue <string>(test, "String"));
            Assert.AreEqual(999, ReflectionUtility.GetPropertyValue <int>(test, "Int"));
            Assert.AreEqual(999, ReflectionUtility.GetPropertyValue <long>(test, "Long"));
            Assert.AreEqual(Decimal.Parse("999,5"), ReflectionUtility.GetPropertyValue <decimal>(test, "Decimal"));
            Assert.AreEqual(new DateTime(1972, 12, 5), ReflectionUtility.GetPropertyValue <DateTime>(test, "Date"));
            Assert.AreEqual(true, ReflectionUtility.GetPropertyValue <bool>(test, "Bool"));
        }
コード例 #3
0
        public static void TestObjectVsTypedNewGetPropertyValue()
        {
            var test = new TestReflectionUtility();
            test.String = "XXX";

            Stopwatch timer = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                ReflectionUtility.GetPropertyValue(test, "String");
            }

            timer.Stop();
            Console.WriteLine(string.Format("Elapsed para obj: {0}", timer.Elapsed));

            timer = Stopwatch.StartNew();
            for (int i = 0; i < 1000000; i++)
            {
                ReflectionUtility.GetPropertyValue<string>(test, "String");
            }

            timer.Stop();
            Console.WriteLine(string.Format("Elapsed para T: {0}", timer.Elapsed));
        }
コード例 #4
0
        public void TestGetPropertyValue()
        {
            var test = new TestReflectionUtility();
            test.String = "XXX";
            test.Int = 999;
            test.Long = 999;
            test.Decimal = Decimal.Parse("999,5");
            test.Date = new DateTime(1972, 12, 5);
            test.Bool = true;

            Assert.AreEqual("XXX", ReflectionUtility.GetPropertyValue<string>(test, "String"));
            Assert.AreEqual(999, ReflectionUtility.GetPropertyValue<int>(test, "Int"));
            Assert.AreEqual(999, ReflectionUtility.GetPropertyValue<long>(test, "Long"));
            Assert.AreEqual(Decimal.Parse("999,5"), ReflectionUtility.GetPropertyValue<decimal>(test, "Decimal"));
            Assert.AreEqual(new DateTime(1972, 12, 5), ReflectionUtility.GetPropertyValue<DateTime>(test, "Date"));
            Assert.AreEqual(true, ReflectionUtility.GetPropertyValue<bool>(test, "Bool"));
        }