public static void SetValue(MemberInfo memberInfo, object instance, object value) { Action <object, object> setter; if (memberInfo is PropertyInfo) { var propertyInfo = memberInfo as PropertyInfo; var key = propertyInfo.GetSetMethod().MethodHandle.Value; if (!setterCache.TryGetValue(key, out setter)) { setterCache.Add(key, setter = EmitHelper.CreatePropertySetterHandler(propertyInfo)); } } else if (memberInfo is FieldInfo) { var fieldInfo = memberInfo as FieldInfo; if (!setterCache.TryGetValue(fieldInfo.FieldHandle.Value, out setter)) { setterCache.Add(fieldInfo.FieldHandle.Value, setter = EmitHelper.CreateFieldSetterHandler(fieldInfo)); } } else { throw new NotImplementedException(); } setter(instance, value); }