//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OAuth.ChannelElements {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Reflection;
///
/// An URI encoder that translates null references as "oob"
/// instead of an empty/missing argument.
///
internal class UriOrOobEncoding : IMessagePartNullEncoder {
///
/// The string constant "oob", used to indicate an out-of-band configuration.
///
private const string OutOfBandConfiguration = "oob";
///
/// Initializes a new instance of the class.
///
public UriOrOobEncoding() {
}
#region IMessagePartNullEncoder Members
///
/// Gets the string representation to include in a serialized message
/// when the message part has a null value.
///
///
public string EncodedNullValue {
get { return OutOfBandConfiguration; }
}
#endregion
#region IMessagePartEncoder Members
///
/// Encodes the specified value.
///
/// The value. Guaranteed to never be null.
///
/// The in string form, ready for message transport.
///
public string Encode(object value) {
Uri uriValue = (Uri)value;
return uriValue.AbsoluteUri;
}
///
/// Decodes the specified value.
///
/// The string value carried by the transport. Guaranteed to never be null, although it may be empty.
///
/// The deserialized form of the given string.
///
/// Thrown when the string value given cannot be decoded into the required object type.
public object Decode(string value) {
if (string.Equals(value, OutOfBandConfiguration, StringComparison.Ordinal)) {
return null;
} else {
return new Uri(value, UriKind.Absolute);
}
}
#endregion
}
}