/// <summary> /// Tries to set the specified member to the specified <paramref name="value"/>. /// </summary> /// <param name="binder">The binder.</param> /// <param name="value">The value to be set.</param> /// <returns><see langword="true"/> if the member is set; otherwise, <see langword="false"/>.</returns> public override bool TrySetMember(SetMemberBinder binder, object value) { Contract.Assume(binder != null); var comparison = binder.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; Contract.Assume(binder.Name != null); var property = ComponentReflection.GetProperty(source, binder.Name, comparison); if (property == null) { return(false); } if (property.IsReadOnly) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Errors.PropertyIsReadOnly, property.Name)); } Action <object, object> action = property.SetValue; var invokeAsync = action.ToAsync(); invokeAsync(source, value); return(true); }
private bool TryGetPropertyObservable(string propertyName, StringComparison comparison, out object result) { Contract.Requires(propertyName != null); Contract.Ensures(!Contract.Result <bool>() || Contract.ValueAtReturn(out result) != null); var property = ComponentReflection.GetProperty(source, propertyName, comparison); if (property == null) { result = null; return(false); } var changed = property.PropertyChanged(source).Select(_ => property.GetValue(source)); #if !SILVERLIGHT Contract.Assume(property.PropertyType != null); #endif result = changed.Coerce(property.PropertyType); return(true); }