/// <summary> /// Sets the value of the property, throwing an exception if the property was already connected. /// </summary> /// <typeparam name="TValue">The property type.</typeparam> /// <param name="property">The connectible property. Must not be <c>null</c>.</param> /// <param name="value">The value to set.</param> /// <seealso cref="IConnectibleProperty{TValue}.TryConnect"/> /// <seealso cref="GetOrConnect{TValue}"/> public static void Connect <TValue>(this IConnectibleProperty <TValue> property, TValue value) { Contract.Requires(property != null); if (!property.TryConnect(value)) { throw new InvalidOperationException("Connectible property was already connected."); } }
/// <summary> /// Sets the value of the property, overwriting any existing value. /// </summary> /// <typeparam name="TValue">The property type.</typeparam> /// <param name="property">The connectible property. Must not be <c>null</c>.</param> /// <param name="value">The value to set.</param> public static void Set <TValue>(this IConnectibleProperty <TValue> property, TValue value) { Contract.Requires(property != null); while (true) { if (property.TryConnect(value)) { return; } property.TryDisconnect(); } }