/// <summary> /// CTOR /// </summary> /// <param name="reason">The reason for early release</param> /// <exception cref="ArgumentOutOfRangeException"><paramref name="reason"/> is not a defined value /// of the <see cref="EarlyReleaseReason"/> enum.</exception> public EarlyReleaseJustificationAttribute(EarlyReleaseReason reason) { switch (reason) { case EarlyReleaseReason.CustomWrapperDispose: case EarlyReleaseReason.DisposingOnError: Justification = reason; break; default: throw new ArgumentOutOfRangeException(nameof(reason), reason, @"The supplied value is not a defined value of the " + $@"{typeof(EarlyReleaseReason).Name} enumeration type."); } }
/// <summary> /// Check if a value is a defined value in the <see cref="EarlyReleaseReason"/> /// enum. /// </summary> /// <param name="reason">the reason to check</param> /// <returns>True only if <paramref name="reason"/> is a defined value of the <see cref="EarlyReleaseReason"/> /// enumeration.</returns> public static bool IsDefined(this EarlyReleaseReason reason) => TheDefinedReasons.Contains(reason);
/// <summary> /// Check if the value of <paramref name="reason"/> is a defined value of the /// <see cref="EarlyReleaseReason"/> enum. /// </summary> /// <param name="reason">the value to check</param> /// <returns>the value</returns> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="reason"/> is /// not a defined value of the <see cref="EarlyReleaseReason"/> enum.</exception> public static EarlyReleaseReason ValueOrThrowIfNDef(this EarlyReleaseReason reason) => TheDefinedReasons.Contains(reason) ? reason : throw new ArgumentOutOfRangeException(nameof(reason), reason, @$ "The supplied reason {reason.ToString()} is not " + @$ "a defined value in the {typeof(EarlyReleaseReason).Name} enum.");
/// <summary> /// Return the value of <paramref name="reason"/> if it is a defined value of the /// <see cref="EarlyReleaseReason"/> enum; otherwise return null /// </summary> /// <param name="reason"></param> /// <returns> the value of <paramref name="reason"/> if it is a defined value of the /// <see cref="EarlyReleaseReason"/> enum; otherwise return null</returns> public static EarlyReleaseReason?ValueOrDefaultIfNDef(this EarlyReleaseReason reason) => TheDefinedReasons.Contains(reason) ? (EarlyReleaseReason?)reason : null;