//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth { using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; using Validation; /// /// Argument validation checks that throw some kind of ArgumentException when they fail (unless otherwise noted). /// internal static class RequiresEx { /// /// Validates some expression describing the acceptable condition for an argument evaluates to true. /// /// The expression that must evaluate to true to avoid an . [Pure, DebuggerStepThrough] internal static void ValidState(bool condition) { if (!condition) { throw new InvalidOperationException(); } } /// /// Validates some expression describing the acceptable condition for an argument evaluates to true. /// /// The expression that must evaluate to true to avoid an . /// The message to include with the exception. [Pure, DebuggerStepThrough] internal static void ValidState(bool condition, string message) { if (!condition) { throw new InvalidOperationException(message); } } /// /// Validates some expression describing the acceptable condition for an argument evaluates to true. /// /// The expression that must evaluate to true to avoid an . /// The unformatted message. /// Formatting arguments. [Pure, DebuggerStepThrough] internal static void ValidState(bool condition, string unformattedMessage, params object[] args) { if (!condition) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, unformattedMessage, args)); } } /// /// Validates that some argument describes a type that is or derives from a required type. /// /// The type that the argument must be or derive from. /// The type given in the argument. /// Name of the parameter. [Pure, DebuggerStepThrough] internal static void NotNullSubtype(Type type, string parameterName) { Requires.NotNull(type, parameterName); Requires.That(typeof(T).IsAssignableFrom(type), parameterName, MessagingStrings.UnexpectedType, typeof(T).FullName, type.FullName); } /// /// Validates some expression describing the acceptable condition for an argument evaluates to true. /// /// The expression that must evaluate to true to avoid an . /// The message. [Pure, DebuggerStepThrough] internal static void Format(bool condition, string message) { if (!condition) { throw new FormatException(message); } } /// /// Throws an if a condition does not evaluate to true. /// /// The expression that must evaluate to true to avoid an . /// The message. [Pure, DebuggerStepThrough] internal static void Support(bool condition, string message) { if (!condition) { throw new NotSupportedException(message); } } } }