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 }
public DataContractJsonSerializerStrategy() { GetCache = new ReflectionUtils.ThreadSafeDictionary <Type, IDictionary <string, ReflectionUtils.GetDelegate> >(GetterValueFactory); SetCache = new ReflectionUtils.ThreadSafeDictionary <Type, IDictionary <string, KeyValuePair <Type, ReflectionUtils.SetDelegate> > >(SetterValueFactory); }
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"); } } }
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 }
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); } } }
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 }
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)](); } } }