コード例 #1
0
        private static void SetPropertyByReflection()
        {
            var cache =
                new ReflectionUtils.ThreadSafeDictionary<PropertyInfo, ReflectionUtils.SetDelegate>(
                    ReflectionUtils.GetSetMethodByReflection);

            var obj = new SimpleClass();
            using (new Profiler("prop.set method invoke", _writer))
            {
                var setter = cache[SamplePropertyInfo];
                setter(obj, "val");
            }

            using (new Profiler(_writer))
            {
                var setter = cache[SamplePropertyInfo];
                setter(obj, "val");
            }

            using (new Profiler(_writer))
            {
                for (int i = 0; i < Loops; i++)
                {
                    var setter = cache[SamplePropertyInfo];
                    setter(obj, "val");
                }
            }
        }
コード例 #2
0
        private static void GetFieldByReflection()
        {
            var cache =
                new ReflectionUtils.ThreadSafeDictionary<FieldInfo, ReflectionUtils.GetDelegate>(
                    ReflectionUtils.GetGetMethodByReflection);

            var obj = new SimpleClass();
            using (new Profiler("field.get method invoke", _writer))
            {
                var getter = cache[SampleFieldInfo];
                var value = getter(obj);
            }

            using (new Profiler(_writer))
            {
                var getter = cache[SampleFieldInfo];
                var value = getter(obj);
            }

            using (new Profiler(_writer))
            {
                for (int i = 0; i < Loops; i++)
                {
                    var getter = cache[SampleFieldInfo];
                    var value = getter(obj);
                }
            }
        }
コード例 #3
0
        private static void SetPropertyByExpression()
        {
            #if !REFLECTION_UTILS_NO_LINQ_EXPRESSION
            var cache =
                new ReflectionUtils.ThreadSafeDictionary<PropertyInfo, ReflectionUtils.SetDelegate>(
                    ReflectionUtils.GetSetMethodByExpression);

            var obj = new SimpleClass();
            using (new Profiler("prop.set expression", _writer))
            {
                var setter = cache[SamplePropertyInfo];
                setter(obj, "val");
            }

            using (new Profiler(_writer))
            {
                var setter = cache[SamplePropertyInfo];
                setter(obj, "val");
            }

            using (new Profiler(_writer))
            {
                for (int i = 0; i < Loops; i++)
                {
                    var setter = cache[SamplePropertyInfo];
                    setter(obj, "val");
                }
            }
            #endif
        }
コード例 #4
0
        private static void GetFieldByExpression()
        {
            #if !REFLECTION_UTILS_NO_LINQ_EXPRESSION
            var cache =
                new ReflectionUtils.ThreadSafeDictionary<FieldInfo, ReflectionUtils.GetDelegate>(
                    ReflectionUtils.GetGetMethodByExpression);

            var obj = new SimpleClass();
            using (new Profiler("field.get expression", _writer))
            {
                var getter = cache[SampleFieldInfo];
                var value = getter(obj);
            }

            using (new Profiler(_writer))
            {
                var getter = cache[SampleFieldInfo];
                var value = getter(obj);
            }

            using (new Profiler(_writer))
            {
                for (int i = 0; i < Loops; i++)
                {
                    var getter = cache[SampleFieldInfo];
                    var value = getter(obj);
                }
            }
            #endif
        }