forked from DotNetOpenAuth/DotNetOpenAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInfoCardErrorUtilities.cs
39 lines (37 loc) · 1.58 KB
/
InfoCardErrorUtilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//-----------------------------------------------------------------------
// <copyright file="InfoCardErrorUtilities.cs" company="Outercurve Foundation">
// Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth {
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Text;
/// <summary>
/// Error reporting methods specific to InfoCard validation.
/// </summary>
internal static class InfoCardErrorUtilities {
/// <summary>
/// Checks a condition and throws an <see cref="InfoCard.InformationCardException"/>
/// if it evaluates to false.
/// </summary>
/// <param name="condition">The condition to check.</param>
/// <param name="errorMessage">The message to include in the exception, if created.</param>
/// <param name="args">The formatting arguments.</param>
/// <exception cref="InfoCard.InformationCardException">Thrown if <paramref name="condition"/> evaluates to <c>false</c>.</exception>
[Pure]
internal static void VerifyInfoCard(bool condition, string errorMessage, params object[] args) {
Requires.NotNull(args, "args");
Contract.Ensures(condition);
Contract.EnsuresOnThrow<InfoCard.InformationCardException>(!condition);
Contract.Assume(errorMessage != null);
if (!condition) {
errorMessage = string.Format(CultureInfo.CurrentCulture, errorMessage, args);
throw new InfoCard.InformationCardException(errorMessage);
}
}
}
}