//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth {
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
///
/// Internal state consistency checks that throw an internal error exception when they fail.
///
internal static class Assumes {
///
/// Validates some expression describing the acceptable condition evaluates to true.
///
/// The expression that must evaluate to true to avoid an internal error exception.
/// The message to include with the exception.
[Pure, DebuggerStepThrough]
internal static void True(bool condition, string message = null) {
if (!condition) {
Fail(message);
}
}
///
/// Validates some expression describing the acceptable condition evaluates to true.
///
/// The expression that must evaluate to true to avoid an internal error exception.
/// The unformatted message.
/// Formatting arguments.
[Pure, DebuggerStepThrough]
internal static void True(bool condition, string unformattedMessage, params object[] args) {
if (!condition) {
Fail(string.Format(CultureInfo.CurrentCulture, unformattedMessage, args));
}
}
///
/// Throws an internal error exception.
///
/// The message.
[Pure, DebuggerStepThrough]
internal static void Fail(string message = null) {
if (message != null) {
throw new InternalErrorException(message);
} else {
throw new InternalErrorException();
}
}
///
/// Throws an internal error exception.
///
/// Nothing. This method always throws.
internal static Exception NotReachable() {
throw new InternalErrorException();
}
///
/// An internal error exception that should never be caught.
///
[SuppressMessage("Microsoft.Design", "CA1064:ExceptionsShouldBePublic", Justification = "This exception should never be caught.")]
[Serializable]
private class InternalErrorException : Exception {
///
/// Initializes a new instance of the class.
///
internal InternalErrorException() {
}
///
/// Initializes a new instance of the class.
///
/// The message.
internal InternalErrorException(string message)
: base(message) {
}
///
/// Initializes a new instance of the class.
///
/// The that holds the serialized object data about the exception being thrown.
/// The that contains contextual information about the source or destination.
/// The parameter is null.
/// The class name is null or is zero (0).
protected InternalErrorException(
SerializationInfo info,
StreamingContext context)
: base(info, context) {
}
}
}
}