summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Core/Messaging/Reflection
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Core/Messaging/Reflection')
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Reflection/IMessagePartFormattingEncoder.cs19
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Reflection/MessagePart.cs14
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Reflection/ValueMapping.cs13
3 files changed, 44 insertions, 2 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/Reflection/IMessagePartFormattingEncoder.cs b/src/DotNetOpenAuth.Core/Messaging/Reflection/IMessagePartFormattingEncoder.cs
new file mode 100644
index 0000000..24bf19d
--- /dev/null
+++ b/src/DotNetOpenAuth.Core/Messaging/Reflection/IMessagePartFormattingEncoder.cs
@@ -0,0 +1,19 @@
+namespace DotNetOpenAuth.Messaging.Reflection {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+
+ /// <summary>
+ /// An interface describing how various objects can be serialized and deserialized between their object and string forms.
+ /// </summary>
+ /// <remarks>
+ /// Implementations of this interface must include a default constructor and must be thread-safe.
+ /// </remarks>
+ public interface IMessagePartFormattingEncoder : IMessagePartEncoder {
+ /// <summary>
+ /// Gets the type of the encoded values produced by this encoder, as they would appear in their preferred form.
+ /// </summary>
+ Type FormattingType { get; }
+ }
+}
diff --git a/src/DotNetOpenAuth.Core/Messaging/Reflection/MessagePart.cs b/src/DotNetOpenAuth.Core/Messaging/Reflection/MessagePart.cs
index b2c4664..76de383 100644
--- a/src/DotNetOpenAuth.Core/Messaging/Reflection/MessagePart.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/Reflection/MessagePart.cs
@@ -206,6 +206,20 @@ namespace DotNetOpenAuth.Messaging.Reflection {
}
/// <summary>
+ /// Gets the type of the encoded values produced by this encoder, as they would appear in their preferred form.
+ /// </summary>
+ internal Type PreferredFormattingType {
+ get {
+ var formattingEncoder = this.converter.Encoder as IMessagePartFormattingEncoder;
+ if (formattingEncoder != null) {
+ return formattingEncoder.FormattingType;
+ }
+
+ return this.MemberDeclaredType;
+ }
+ }
+
+ /// <summary>
/// Sets the member of a given message to some given value.
/// Used in deserialization.
/// </summary>
diff --git a/src/DotNetOpenAuth.Core/Messaging/Reflection/ValueMapping.cs b/src/DotNetOpenAuth.Core/Messaging/Reflection/ValueMapping.cs
index bc12f5d..4139f52 100644
--- a/src/DotNetOpenAuth.Core/Messaging/Reflection/ValueMapping.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/Reflection/ValueMapping.cs
@@ -35,7 +35,8 @@ namespace DotNetOpenAuth.Messaging.Reflection {
/// <param name="toString">The mapping function that converts some custom value to a string.</param>
/// <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) {
+ internal ValueMapping(Func<object, string> toString, Func<object, string> toOriginalString, Func<string, object> toValue)
+ : this() {
Requires.NotNull(toString, "toString");
Requires.NotNull(toValue, "toValue");
@@ -48,8 +49,11 @@ namespace DotNetOpenAuth.Messaging.Reflection {
/// Initializes a new instance of the <see cref="ValueMapping"/> struct.
/// </summary>
/// <param name="encoder">The encoder.</param>
- internal ValueMapping(IMessagePartEncoder encoder) {
+ internal ValueMapping(IMessagePartEncoder encoder)
+ : this() {
Requires.NotNull(encoder, "encoder");
+
+ this.Encoder = encoder;
var nullEncoder = encoder as IMessagePartNullEncoder;
string nullString = nullEncoder != null ? nullEncoder.EncodedNullValue : null;
@@ -63,5 +67,10 @@ namespace DotNetOpenAuth.Messaging.Reflection {
this.StringToValue = str => (str != null) ? encoder.Decode(str) : null;
this.ValueToOriginalString = obj => (obj != null) ? originalStringEncode(obj) : nullString;
}
+
+ /// <summary>
+ /// Gets the encoder.
+ /// </summary>
+ internal IMessagePartEncoder Encoder { get; private set; }
}
}