private static void GetConstructorByExpression() { #if !REFLECTION_UTILS_NO_LINQ_EXPRESSION var cache = new ReflectionUtils.ThreadSafeDictionary <Type, ReflectionUtils.ConstructorDelegate>( type => ReflectionUtils.GetConstructorByExpression(type)); using (new Profiler("ctor expression", _writer)) { var obj = cache[typeof(SimpleClass)](); } using (new Profiler(_writer)) { var obj = cache[typeof(SimpleClass)](); } using (new Profiler(_writer)) { for (int i = 0; i < Loops; i++) { var obj = cache[typeof(SimpleClass)](); } } #endif }
private static void SetFieldByExpression() { #if !REFLECTION_UTILS_NO_LINQ_EXPRESSION var cache = new ReflectionUtils.ThreadSafeDictionary <FieldInfo, ReflectionUtils.SetDelegate>( ReflectionUtils.GetSetMethodByExpression); var obj = new SimpleClass(); using (new Profiler("field.set expression", _writer)) { var setter = cache[SampleFieldInfo]; setter(obj, "val"); } using (new Profiler(_writer)) { var setter = cache[SampleFieldInfo]; setter(obj, "val"); } using (new Profiler(_writer)) { for (int i = 0; i < Loops; i++) { var setter = cache[SampleFieldInfo]; setter(obj, "val"); } } #endif }
private static void SetFieldByReflection() { var cache = new ReflectionUtils.ThreadSafeDictionary <FieldInfo, ReflectionUtils.SetDelegate>( ReflectionUtils.GetSetMethodByReflection); var obj = new SimpleClass(); using (new Profiler("field.set method invoke", _writer)) { var setter = cache[SampleFieldInfo]; setter(obj, "val"); } using (new Profiler(_writer)) { var setter = cache[SampleFieldInfo]; setter(obj, "val"); } using (new Profiler(_writer)) { for (int i = 0; i < Loops; i++) { var setter = cache[SampleFieldInfo]; setter(obj, "val"); } } }
private static void GetPropertyByExpression() { #if !REFLECTION_UTILS_NO_LINQ_EXPRESSION var cache = new ReflectionUtils.ThreadSafeDictionary <PropertyInfo, ReflectionUtils.GetDelegate>( ReflectionUtils.GetGetMethodByExpression); var obj = new SimpleClass(); using (new Profiler("prop.get expression", _writer)) { var getter = cache[SamplePropertyInfo]; var value = getter(obj); } using (new Profiler(_writer)) { var getter = cache[SamplePropertyInfo]; var value = getter(obj); } using (new Profiler(_writer)) { for (int i = 0; i < Loops; i++) { var getter = cache[SamplePropertyInfo]; var value = getter(obj); } } #endif }
private static void GetPropertyByReflection() { var cache = new ReflectionUtils.ThreadSafeDictionary <PropertyInfo, ReflectionUtils.GetDelegate>( ReflectionUtils.GetGetMethodByReflection); var obj = new SimpleClass(); using (new Profiler("prop.get method invoke", _writer)) { var getter = cache[SamplePropertyInfo]; var value = getter(obj); } using (new Profiler(_writer)) { var getter = cache[SamplePropertyInfo]; var value = getter(obj); } using (new Profiler(_writer)) { for (int i = 0; i < Loops; i++) { var getter = cache[SamplePropertyInfo]; var value = getter(obj); } } }
private static void GetConstructorByReflection() { var cache = new ReflectionUtils.ThreadSafeDictionary <Type, ReflectionUtils.ConstructorDelegate>( type => ReflectionUtils.GetConstructorByReflection(type)); using (new Profiler("ctor method invoke", _writer)) { var obj = cache[typeof(SimpleClass)](); } using (new Profiler(_writer)) { var obj = cache[typeof(SimpleClass)](); } using (new Profiler(_writer)) { for (int i = 0; i < Loops; i++) { var obj = cache[typeof(SimpleClass)](); } } }