using Chernobyl.Event; using Chernobyl.Readiness; using Chernobyl.Utility; namespace Chernobyl.Values { /// /// An type that holds the non-null value held /// by a . /// /// The type that is to be held. public class NotNull : HeldValue where T : class { /// /// Initializes a new instance of the class. /// /// The instance whose contained value is to be /// considered ready when it is no longer null. public NotNull(IValue value) { value.ThrowIfNull("value"); value.Provide += OnValueProvide; } /// /// An event handler that is invoked when the value is changed. This /// method ensures the value of this instance is maintained. /// /// The sender of the event. /// The arguments containing the changed value. void OnValueProvide(object sender, ValueChangedEventArgs e) { if (e.NewValue != null) Value = e.NewValue; else IsReady = false; } } /// /// Utility methods and extensions for . /// public static class NotNullExtensions { /// /// Returns an instance created with the /// provided. /// /// The type contained within . /// The with which to create /// the . /// The instance. public static IValue NotNull(this IValue value) where T : class { return new NotNull(value); } } }