diff options
4 files changed, 16 insertions, 74 deletions
diff --git a/src/DotNetOpenAuth/ContractRuntimeFailureMethods.cs b/src/DotNetOpenAuth/ContractRuntimeFailureMethods.cs index 9fb1f63..5a6c465 100644 --- a/src/DotNetOpenAuth/ContractRuntimeFailureMethods.cs +++ b/src/DotNetOpenAuth/ContractRuntimeFailureMethods.cs @@ -19,71 +19,10 @@ namespace DotNetOpenAuth { /// The Code Contracts assembly rewriter (ccrewrite) tool causes all calls to Contract.*() /// to redirect to this class. /// </remarks> - public static class ContractRuntimeFailureMethods { + internal static class ContractRuntimeFailureMethods { [DebuggerStepThrough] - public static void Requires(bool condition, string userMessage, string conditionText) { - if (!condition) { - throw new ArgumentException(userMessage ?? conditionText); - } - } - - [DebuggerStepThrough] - public static void Ensures(bool condition, string userMessage, string conditionText) { - if (!condition) { - throw new InternalErrorException(userMessage ?? conditionText); - } - } - - [DebuggerStepThrough] - public static void EnsuresOnThrow(bool condition, string userMessage, string conditionText) { - if (!condition) { - throw new InternalErrorException(userMessage ?? conditionText); - } - } - - [DebuggerStepThrough] - public static void Assert(bool condition, string userMessage, string conditionText) { - if (!condition) { - throw new InternalErrorException(userMessage ?? conditionText); - } - } - - [DebuggerStepThrough] - public static void Assume(bool condition, string userMessage, string conditionText) { - if (!condition) { - throw new InternalErrorException(userMessage ?? conditionText); - } - } - - [DebuggerStepThrough] - public static void Invariant(bool condition, string userMessage, string conditionText) { - if (!condition) { - throw new InternalErrorException(userMessage ?? conditionText); - } - } - - [DebuggerStepThrough] - public static void Failure(ContractFailureKind failureKind, string userProvidedMessage, string condition, Exception originalException) { - switch (failureKind) { - case ContractFailureKind.Assert: - Assert(false, userProvidedMessage, condition); - break; - case ContractFailureKind.Assume: - Assume(false, userProvidedMessage, condition); - break; - case ContractFailureKind.Invariant: - Invariant(false, userProvidedMessage, condition); - break; - case ContractFailureKind.Postcondition: - Ensures(false, userProvidedMessage, condition); - break; - case ContractFailureKind.Precondition: - Requires(false, userProvidedMessage, condition); - break; - default: - ErrorUtilities.ThrowInternal(userProvidedMessage ?? condition); - break; - } + internal static void ReportFailure(ContractFailureKind failureKind, string userProvidedMessage, string condition, Exception originalException) { + ErrorUtilities.ThrowInternal(userProvidedMessage ?? condition); } } } diff --git a/src/DotNetOpenAuth/Messaging/Reflection/MessageDictionary.cs b/src/DotNetOpenAuth/Messaging/Reflection/MessageDictionary.cs index bd11709..641ed3a 100644 --- a/src/DotNetOpenAuth/Messaging/Reflection/MessageDictionary.cs +++ b/src/DotNetOpenAuth/Messaging/Reflection/MessageDictionary.cs @@ -391,8 +391,8 @@ namespace DotNetOpenAuth.Messaging.Reflection { [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Called by code contracts.")] [ContractInvariantMethod] protected void ObjectInvariant() { - Contract.Ensures(this.message != null); - Contract.Ensures(this.description != null); + Contract.Invariant(this.Message != null); + Contract.Invariant(this.Description != null); } #endif } diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/AuthenticationRequest.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/AuthenticationRequest.cs index 233186b..5b8a865 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/AuthenticationRequest.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/AuthenticationRequest.cs @@ -319,11 +319,11 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// before calling this method. /// </remarks> private static IEnumerable<AuthenticationRequest> CreateInternal(Identifier userSuppliedIdentifier, OpenIdRelyingParty relyingParty, Realm realm, Uri returnToUrl, IEnumerable<ServiceEndpoint> serviceEndpoints, bool createNewAssociationsAsNeeded) { - Contract.Requires(userSuppliedIdentifier != null); - Contract.Requires(relyingParty != null); - Contract.Requires(realm != null); - Contract.Requires(serviceEndpoints != null); - Contract.Ensures(Contract.Result<IEnumerable<AuthenticationRequest>>() != null); + // Can't use code contracts here because this is a yield return method. + ErrorUtilities.VerifyArgumentNotNull(userSuppliedIdentifier, "userSuppliedIdentifier"); + ErrorUtilities.VerifyArgumentNotNull(relyingParty, "relyingParty"); + ErrorUtilities.VerifyArgumentNotNull(realm, "realm"); + ErrorUtilities.VerifyArgumentNotNull(serviceEndpoints, "serviceEndpoints"); Logger.Yadis.InfoFormat("Performing discovery on user-supplied identifier: {0}", userSuppliedIdentifier); IEnumerable<ServiceEndpoint> endpoints = FilterAndSortEndpoints(serviceEndpoints, relyingParty); diff --git a/src/DotNetOpenAuth/Util.cs b/src/DotNetOpenAuth/Util.cs index 1a67966..4d0008c 100644 --- a/src/DotNetOpenAuth/Util.cs +++ b/src/DotNetOpenAuth/Util.cs @@ -11,6 +11,7 @@ namespace DotNetOpenAuth { using System.Net; using System.Reflection; using System.Text; + using DotNetOpenAuth.Messaging; /// <summary> /// A grab-bag utility class. @@ -74,7 +75,7 @@ namespace DotNetOpenAuth { return new DelayedToString<IEnumerable<KeyValuePair<K, V>>>( pairs, p => { - Contract.Requires(pairs != null); + ErrorUtilities.VerifyArgumentNotNull(pairs, "pairs"); var dictionary = pairs as IDictionary<K, V>; StringBuilder sb = new StringBuilder(dictionary != null ? dictionary.Count * 40 : 200); foreach (var pair in pairs) { @@ -106,9 +107,11 @@ namespace DotNetOpenAuth { return new DelayedToString<IEnumerable<T>>( list, l => { - Contract.Requires(l != null); + // Code contracts not allowed in generator methods. + ErrorUtilities.VerifyArgumentNotNull(l, "l"); + string newLine = Environment.NewLine; - Contract.Assume(newLine != null && newLine.Length > 0); + ////Contract.Assume(newLine != null && newLine.Length > 0); StringBuilder sb = new StringBuilder(); if (multiLineElements) { sb.AppendLine("[{"); |