diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2011-09-17 17:19:26 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2011-09-17 17:19:26 -0700 |
commit | bab1c76d35421a3d2a1608e6f3e66d67b4fbdb09 (patch) | |
tree | cc27e38eb52d26bb2a977b2d0335f0f04a23c746 /src/DotNetOpenAuth.Messaging/Messaging/Reflection | |
parent | 344c333ecd76785a77b8a1a56e1bc360ae159d04 (diff) | |
download | DotNetOpenAuth-bab1c76d35421a3d2a1608e6f3e66d67b4fbdb09.zip DotNetOpenAuth-bab1c76d35421a3d2a1608e6f3e66d67b4fbdb09.tar.gz DotNetOpenAuth-bab1c76d35421a3d2a1608e6f3e66d67b4fbdb09.tar.bz2 |
DotNetOpenAuth.Messaging no longer relies on ccrewrite.exe
Diffstat (limited to 'src/DotNetOpenAuth.Messaging/Messaging/Reflection')
6 files changed, 38 insertions, 41 deletions
diff --git a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/IMessagePartEncoder.cs b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/IMessagePartEncoder.cs index 03534f2..bbb3737 100644 --- a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/IMessagePartEncoder.cs +++ b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/IMessagePartEncoder.cs @@ -56,7 +56,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// The <paramref name="value"/> in string form, ready for message transport. /// </returns> string IMessagePartEncoder.Encode(object value) { - Contract.Requires<ArgumentNullException>(value != null); + Requires.NotNull(value, "value"); throw new NotImplementedException(); } @@ -69,7 +69,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// </returns> /// <exception cref="FormatException">Thrown when the string value given cannot be decoded into the required object type.</exception> object IMessagePartEncoder.Decode(string value) { - Contract.Requires<ArgumentNullException>(value != null); + Requires.NotNull(value, "value"); throw new NotImplementedException(); } diff --git a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessageDescription.cs b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessageDescription.cs index 7dbab80..9a8098b 100644 --- a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessageDescription.cs +++ b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessageDescription.cs @@ -30,9 +30,8 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <param name="messageType">Type of the message.</param> /// <param name="messageVersion">The message version.</param> internal MessageDescription(Type messageType, Version messageVersion) { - Contract.Requires<ArgumentNullException>(messageType != null); - Contract.Requires<ArgumentException>(typeof(IMessage).IsAssignableFrom(messageType)); - Contract.Requires<ArgumentNullException>(messageVersion != null); + Requires.NotNullSubtype<IMessage>(messageType, "messageType"); + Requires.NotNull(messageVersion, "messageVersion"); this.MessageType = messageType; this.MessageVersion = messageVersion; @@ -80,7 +79,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <returns>The dictionary accessor to the message</returns> [Pure] internal MessageDictionary GetDictionary(IMessage message) { - Contract.Requires<ArgumentNullException>(message != null); + Requires.NotNull(message, "message"); Contract.Ensures(Contract.Result<MessageDictionary>() != null); return this.GetDictionary(message, false); } @@ -93,7 +92,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <returns>The dictionary accessor to the message</returns> [Pure] internal MessageDictionary GetDictionary(IMessage message, bool getOriginalValues) { - Contract.Requires<ArgumentNullException>(message != null); + Requires.NotNull(message, "message"); Contract.Ensures(Contract.Result<MessageDictionary>() != null); return new MessageDictionary(message, this, getOriginalValues); } @@ -123,11 +122,11 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <param name="parts">The key/value pairs of the serialized message.</param> /// <returns>A value indicating whether the provided data fits the message's basic requirements.</returns> internal bool CheckMessagePartsPassBasicValidation(IDictionary<string, string> parts) { - Contract.Requires<ArgumentNullException>(parts != null); + Requires.NotNull(parts, "parts"); return this.CheckRequiredMessagePartsArePresent(parts.Keys, false) && - this.CheckRequiredProtocolMessagePartsAreNotEmpty(parts, false) && - this.CheckMessagePartsConstantValues(parts, false); + this.CheckRequiredProtocolMessagePartsAreNotEmpty(parts, false) && + this.CheckMessagePartsConstantValues(parts, false); } /// <summary> @@ -142,7 +141,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// if <paramref name="throwOnFailure"/> is <c>true</c>. /// </exception> private bool CheckRequiredMessagePartsArePresent(IEnumerable<string> keys, bool throwOnFailure) { - Contract.Requires<ArgumentNullException>(keys != null); + Requires.NotNull(keys, "keys"); var missingKeys = (from part in this.Mapping.Values where part.IsRequired && !keys.Contains(part.Name) @@ -176,7 +175,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// if <paramref name="throwOnFailure"/> is <c>true</c>. /// </exception> private bool CheckRequiredProtocolMessagePartsAreNotEmpty(IDictionary<string, string> partValues, bool throwOnFailure) { - Contract.Requires<ArgumentNullException>(partValues != null); + Requires.NotNull(partValues, "partValues"); string value; var emptyValuedKeys = (from part in this.Mapping.Values @@ -206,15 +205,14 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <param name="partValues">The part values.</param> /// <param name="throwOnFailure">if set to <c>true</c>, this method will throw on failure.</param> /// <returns>A value indicating whether all the requirements are met.</returns> - private bool CheckMessagePartsConstantValues(IDictionary<string, string> partValues, bool throwOnFailure) - { - Contract.Requires<ArgumentNullException>(partValues != null); + private bool CheckMessagePartsConstantValues(IDictionary<string, string> partValues, bool throwOnFailure) { + Requires.NotNull(partValues, "partValues"); var badConstantValues = (from part in this.Mapping.Values - where part.IsConstantValueAvailableStatically - where partValues.ContainsKey(part.Name) - where !string.Equals(partValues[part.Name], part.StaticConstantValue, StringComparison.Ordinal) - select part.Name).ToArray(); + where part.IsConstantValueAvailableStatically + where partValues.ContainsKey(part.Name) + where !string.Equals(partValues[part.Name], part.StaticConstantValue, StringComparison.Ordinal) + select part.Name).ToArray(); if (badConstantValues.Length > 0) { if (throwOnFailure) { ErrorUtilities.ThrowProtocol( diff --git a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessageDescriptionCollection.cs b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessageDescriptionCollection.cs index e332fc4..79ef172 100644 --- a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessageDescriptionCollection.cs +++ b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessageDescriptionCollection.cs @@ -64,9 +64,8 @@ namespace DotNetOpenAuth.Messaging.Reflection { [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Diagnostics.Contracts.__ContractsRuntime.Assume(System.Boolean,System.String,System.String)", Justification = "No localization required.")] [Pure] internal MessageDescription Get(Type messageType, Version messageVersion) { - Contract.Requires<ArgumentNullException>(messageType != null); - Contract.Requires<ArgumentException>(typeof(IMessage).IsAssignableFrom(messageType)); - Contract.Requires<ArgumentNullException>(messageVersion != null); + Requires.NotNullSubtype<IMessage>(messageType, "messageType"); + Requires.NotNull(messageVersion, "messageVersion"); Contract.Ensures(Contract.Result<MessageDescription>() != null); MessageTypeAndVersion key = new MessageTypeAndVersion(messageType, messageVersion); @@ -94,7 +93,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// </returns> [Pure] internal MessageDescription Get(IMessage message) { - Contract.Requires<ArgumentNullException>(message != null); + Requires.NotNull(message, "message"); Contract.Ensures(Contract.Result<MessageDescription>() != null); return this.Get(message.GetType(), message.Version); } @@ -106,7 +105,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <returns>The dictionary.</returns> [Pure] internal MessageDictionary GetAccessor(IMessage message) { - Contract.Requires<ArgumentNullException>(message != null); + Requires.NotNull(message, "message"); return this.GetAccessor(message, false); } @@ -118,7 +117,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <returns>The dictionary.</returns> [Pure] internal MessageDictionary GetAccessor(IMessage message, bool getOriginalValues) { - Contract.Requires<ArgumentNullException>(message != null); + Requires.NotNull(message, "message"); return this.Get(message).GetDictionary(message, getOriginalValues); } @@ -143,8 +142,8 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <param name="messageType">Type of the message.</param> /// <param name="messageVersion">The message version.</param> internal MessageTypeAndVersion(Type messageType, Version messageVersion) { - Contract.Requires<ArgumentNullException>(messageType != null); - Contract.Requires<ArgumentNullException>(messageVersion != null); + Requires.NotNull(messageType, "messageType"); + Requires.NotNull(messageVersion, "messageVersion"); this.type = messageType; this.version = messageVersion; diff --git a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessageDictionary.cs b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessageDictionary.cs index 2b60a9c..54e2dd5 100644 --- a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessageDictionary.cs +++ b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessageDictionary.cs @@ -42,8 +42,8 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <param name="getOriginalValues">A value indicating whether this message dictionary will retrieve original values instead of normalized ones.</param> [Pure] internal MessageDictionary(IMessage message, MessageDescription description, bool getOriginalValues) { - Contract.Requires<ArgumentNullException>(message != null); - Contract.Requires<ArgumentNullException>(description != null); + Requires.NotNull(message, "message"); + Requires.NotNull(description, "description"); this.message = message; this.description = description; @@ -389,7 +389,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// </summary> /// <param name="fields">The data to load into the message.</param> public void Deserialize(IDictionary<string, string> fields) { - Contract.Requires<ArgumentNullException>(fields != null); + Requires.NotNull(fields, "fields"); this.Serializer.Deserialize(fields, this); } diff --git a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessagePart.cs b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessagePart.cs index 83f489a..f439c4d 100644 --- a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessagePart.cs +++ b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessagePart.cs @@ -105,9 +105,9 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// </param> [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Unavoidable"), SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "Code contracts requires it.")] internal MessagePart(MemberInfo member, MessagePartAttribute attribute) { - Contract.Requires<ArgumentNullException>(member != null); - Contract.Requires<ArgumentException>(member is FieldInfo || member is PropertyInfo); - Contract.Requires<ArgumentNullException>(attribute != null); + Requires.NotNull(member, "member"); + Requires.True(member is FieldInfo || member is PropertyInfo, "member"); + Requires.NotNull(attribute, "attribute"); this.field = member as FieldInfo; this.property = member as PropertyInfo; @@ -199,7 +199,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// </summary> internal string StaticConstantValue { get { - Contract.Requires<InvalidOperationException>(this.IsConstantValueAvailableStatically); + Requires.ValidState(this.IsConstantValueAvailableStatically); return this.ToString(this.field.GetValue(null), false); } } @@ -220,8 +220,8 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <param name="toValue">The function to convert a string to the custom type.</param> [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Diagnostics.Contracts.__ContractsRuntime.Requires<System.ArgumentNullException>(System.Boolean,System.String,System.String)", Justification = "Code contracts"), SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "toString", Justification = "Code contracts"), SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "toValue", Justification = "Code contracts")] internal static void Map<T>(Func<T, string> toString, Func<T, string> toOriginalString, Func<string, T> toValue) { - Contract.Requires<ArgumentNullException>(toString != null); - Contract.Requires<ArgumentNullException>(toValue != null); + Requires.NotNull(toString, "toString"); + Requires.NotNull(toValue, "toValue"); if (toOriginalString == null) { toOriginalString = toString; @@ -240,7 +240,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <param name="message">The message instance containing the member whose value should be set.</param> /// <param name="value">The string representation of the value to set.</param> internal void SetValue(IMessage message, string value) { - Contract.Requires<ArgumentNullException>(message != null); + Requires.NotNull(message, "message"); try { if (this.IsConstantValue) { @@ -343,7 +343,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <param name="messagePartEncoder">The message part encoder type.</param> /// <returns>An instance of the desired encoder.</returns> private static IMessagePartEncoder GetEncoder(Type messagePartEncoder) { - Contract.Requires<ArgumentNullException>(messagePartEncoder != null); + Requires.NotNull(messagePartEncoder, "messagePartEncoder"); Contract.Ensures(Contract.Result<IMessagePartEncoder>() != null); IMessagePartEncoder encoder; diff --git a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/ValueMapping.cs b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/ValueMapping.cs index b0b8b47..9c0fa83 100644 --- a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/ValueMapping.cs +++ b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/ValueMapping.cs @@ -36,8 +36,8 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// <param name="toOriginalString">The mapping function that converts some custom value to its original (non-normalized) string. May be null if the same as the <paramref name="toString"/> function.</param> /// <param name="toValue">The mapping function that converts a string to some custom value.</param> internal ValueMapping(Func<object, string> toString, Func<object, string> toOriginalString, Func<string, object> toValue) { - Contract.Requires<ArgumentNullException>(toString != null); - Contract.Requires<ArgumentNullException>(toValue != null); + Requires.NotNull(toString, "toString"); + Requires.NotNull(toValue, "toValue"); this.ValueToString = toString; this.ValueToOriginalString = toOriginalString ?? toString; @@ -49,7 +49,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { /// </summary> /// <param name="encoder">The encoder.</param> internal ValueMapping(IMessagePartEncoder encoder) { - Contract.Requires<ArgumentNullException>(encoder != null); + Requires.NotNull(encoder, "encoder"); var nullEncoder = encoder as IMessagePartNullEncoder; string nullString = nullEncoder != null ? nullEncoder.EncodedNullValue : null; |