private static void SetValueWithCoercion(object target, DynamicMemberHandle handle, object value) { if (value != null) { Type memberType = handle.MemberType; Type underlyingType = GetUnderlyingType(value.GetType()); object arg = CoerceValue(memberType, underlyingType, value); if (arg != null) { handle.DynamicMemberSet(target, arg); } } }
/// <summary> /// Invokes a property setter using dynamic /// method invocation. /// </summary> /// <param name="obj">Target object.</param> /// <param name="property">Property to invoke.</param> /// <param name="value">New value for property.</param> public static void CallPropertySetter(object obj, string property, object value) { DynamicMemberHandle cachedProperty = MethodCaller.GetCachedProperty(obj.GetType(), property); cachedProperty.DynamicMemberSet(obj, value); }