/// <summary> /// Adds the <see cref="SourceItemChanged(object, ItemChangedEventArgs)"/> event handler to the /// <see cref="SourceItem"/>'s <see cref="Changed"/> event. /// </summary> /// <returns>A Result containing the result of the operation.</returns> /// <threadsafety instance="true"/> public virtual Result SubscribeToSource() { Result retVal = new Result(); if (Source == ItemSource.Item) { sourceItemLock.EnterWriteLock(); try { SourceItem.Changed += SourceItemChanged; SourceItem.SubscriptionsChanged(); IsSubscribedToSource = true; } finally { sourceItemLock.ExitWriteLock(); } } else if (Source == ItemSource.Provider) { providerLock.EnterWriteLock(); try { if (Provider is ISubscribable) { ((ISubscribable)Provider).Subscribe(this, value => ChangeValue(value)); IsSubscribedToSource = true; } else { retVal.AddError("Unable to subscribe to source; the source Item Provider is not subscribable."); } } finally { providerLock.ExitWriteLock(); } } else { retVal.AddError("Unable to subscribe to source; the source Item is either not specified or hasn't been resolved."); } return(retVal); }