/// <summary> /// Sets the value of the <see cref="Root"/> property to the instance returned by the specified /// callback function. The callback function MUST NOT return null. /// <para>NOTE: This method should only be called at the beginning of an application. Any calls to this method after /// the <see cref="Root"/> property has been accessed (i.e. when <see cref="IsLocked"/> is true) will /// result in an <see cref="InvalidOperationException"/> being thrown.</para> /// </summary> /// <param name="getRoot"> /// A function that returns the instance of <see cref="IConfiguration"/> to be used as the <see cref="Root"/> /// property. This function MUST NOT return null. /// </param> /// <exception cref="ArgumentNullException">If the <paramref name="getRoot"/> parameter is null.</exception> /// <exception cref="InvalidOperationException">If the <see cref="IsLocked"/> property is true.</exception> public static void SetRoot(Func <IConfiguration> getRoot) { if (getRoot == null) { throw new ArgumentNullException(nameof(getRoot)); } _root.SetValue(getRoot); }
public void HasDefaultValueIsFalseWhenSetValueIsCalled() { var semimutable = new Semimutable <int>(1); semimutable.SetValue(() => 2); Assert.False(semimutable.HasDefaultValue); }
public void CanChangeValuePropertyWithTheSetValueMethod() { var semimutable = new Semimutable <int>(1); semimutable.SetValue(() => 2); Assert.Equal(2, semimutable.Value); }
public void CallingTheSetValueMethodThrowsWhenIsLockedIsTrue() { var semimutable = new Semimutable <int>(1); semimutable.LockValue(); Assert.Throws <InvalidOperationException>(() => semimutable.SetValue(() => 2)); }
/// <summary> /// Sets the current instance of <see cref="IMessagingScenarioFactory"/> used for operations /// of the <see cref="MessagingScenarioFactory"/> class. /// </summary> /// <param name="messagingScenarioFactory"> /// The instance of <see cref="IMessagingScenarioFactory"/> to be used for operations of the /// <see cref="MessagingScenarioFactory"/> class. /// </param> public static void SetCurrent(IMessagingScenarioFactory messagingScenarioFactory) { _messagingScenarioFactory.SetValue(() => { _fallbackMessagingScenarioFactory = null; return(messagingScenarioFactory); }); }
/// <summary> /// Sets the value of the <see cref="Current"/> property. /// </summary> /// <param name="crypto"> /// The new value for the <see cref="Current"/> property, or null to set /// to the default <see cref="ICrypto"/>. /// </param> /// <remarks> /// Each method of the <see cref="Crypto"/> class ultimately uses the value /// of the <see cref="Current"/> property and calls one of its methods. /// </remarks> public static void SetCurrent(ICrypto crypto) => _current.SetValue(() => crypto ?? GetDefaultCrypto());
/// <summary> /// Sets the value of the <see cref="EncryptionMechanism"/> property. /// </summary> /// <param name="cryptoEncryptionMechanism">The new value of the <see cref="EncryptionMechanism"/> property.</param> /// <remarks> /// Each method of the <see cref="SerializingCrypto"/> class ultimately uses the value /// of this property and calls one of its methods. /// </remarks> public static void SetEncryptionMechanism(CryptoEncryptionMechanism cryptoEncryptionMechanism) { _encryptionMechanism.SetValue(() => cryptoEncryptionMechanism ?? GetDefaultCryptoEncryptionMechanism()); }