public static bool TrySetValue <TResult>([CanBeNull] this BindingActionValue actionValue, object[] args, out TResult result) { result = default(TResult); if (actionValue == null) { return(false); } object source = actionValue.MemberSource.Target; if (actionValue.MemberSource.Target == null) { return(false); } try { object value = actionValue.Member.SetValue(source, args); if (value is TResult) { result = (TResult)value; } } catch (Exception exception) { Tracer.Error(exception.Flatten(false)); return(false); } return(true); }
public void SetValue(BindingActionValue currentValue, object newValue, IBindingPathMembers pathMembers) { _path = pathMembers.Path; //it's normal here. lock (this) { if (_currentValue != null && Equals(currentValue.Member, _currentValue.Member) && Equals(_currentValue.MemberSource.Target, currentValue.MemberSource.Target)) { SetValue(newValue, pathMembers); } else { UnsubscribeEventHandler(); currentValue.TrySetValue(new object[] { this }, out _subscriber); if (_subscriber != null) { if (_path.IsDebuggable) { DebugInfo($"Binding subscribed to event: '{pathMembers.LastMember.Path}'", new object[] { pathMembers }); } _currentValue = currentValue; SetValue(newValue, pathMembers); } } } }
public override void Dispose() { _formatExpression = null; _getSourceMemberValue = null; for (int index = 0; index < _sources.Length; index++) { _sources[index].Dispose(); } base.Dispose(); }
protected override object GetValueInternal(IBindingMemberInfo targetMember, IDataContext context, bool throwOnError) { if (BindingMemberType.Event.EqualsWithoutNullCheck(targetMember.MemberType)) { if (_getSourceMemberValue == null) { _getSourceMemberValue = new BindingActionValue(this, BindingMemberInfo.MultiBindingSourceAccessorMember); } return(_getSourceMemberValue); } return(base.GetValueInternal(targetMember, context, throwOnError)); }
private void TryRegisterEvent(BindingActionValue bindingActionValue, object newValue, IDataContext context, IBindingPathMembers pathMembers) { if (newValue == null && _closure == null) { return; } if (_closure == null) { Interlocked.CompareExchange(ref _closure, new EventClosure(_bindingSource, _toggleEnabledState && IsTarget, Parameters?.CommandParameterDelegate), null); } _closure.LastContext = context; _closure.SetValue(bindingActionValue, newValue, pathMembers); }
public static object GetValue([CanBeNull] this BindingActionValue actionValue, object[] args) { object source = actionValue?.MemberSource.Target; if (source == null) { return(BindingConstants.UnsetValue); } try { return(actionValue.Member.GetValue(source, args)); } catch (Exception exception) { Tracer.Error(exception.Flatten(false)); return(BindingConstants.UnsetValue); } }
public void SetValue(BindingActionValue currentValue, object newValue) { //it's normal here. lock (this) { if (_currentValue != null && Equals(currentValue.Member, _currentValue.Member) && Equals(_currentValue.MemberSource.Target, currentValue.MemberSource.Target)) { SetValue(newValue); } else { UnsubscribeEventHandler(); currentValue.TrySetValue(new object[] { this }, out _subscriber); if (_subscriber != null) { _currentValue = currentValue; SetValue(newValue); } } } }