//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Messaging {
using System;
using System.Diagnostics.Contracts;
///
/// A serializer for -derived types
///
/// The DataBag-derived type that is to be serialized/deserialized.
[ContractClass(typeof(IDataBagFormatterContract<>))]
internal interface IDataBagFormatter where T : DataBag {
///
/// Serializes the specified message.
///
/// The message to serialize. Must not be null.
/// A non-null, non-empty value.
string Serialize(T message);
///
/// Deserializes a .
///
/// The instance to deserialize into
/// The serialized form of the to deserialize. Must not be null or empty.
/// The message that contains the serialized value. May be null if no carrying message is applicable.
/// The name of the parameter whose value is to be deserialized. Used for error message generation, but may be null.
void Deserialize(T message, string data, IProtocolMessage containingMessage = null, string messagePartName = null);
}
///
/// Contract class for the IDataBagFormatter interface.
///
/// The type of DataBag to serialize.
[ContractClassFor(typeof(IDataBagFormatter<>))]
internal abstract class IDataBagFormatterContract : IDataBagFormatter where T : DataBag, new() {
///
/// Prevents a default instance of the class from being created.
///
private IDataBagFormatterContract() {
}
#region IDataBagFormatter Members
///
/// Serializes the specified message.
///
/// The message to serialize. Must not be null.
/// A non-null, non-empty value.
string IDataBagFormatter.Serialize(T message) {
Requires.NotNull(message, "message");
Contract.Ensures(!string.IsNullOrEmpty(Contract.Result()));
throw new System.NotImplementedException();
}
///
/// Deserializes a .
///
/// The instance to deserialize into
/// The serialized form of the to deserialize. Must not be null or empty.
/// The message that contains the serialized value. Must not be nulll.
/// Name of the message part whose value is to be deserialized. Used for exception messages.
void IDataBagFormatter.Deserialize(T message, string data, IProtocolMessage containingMessage, string messagePartName) {
Requires.NotNull(message, "message");
Requires.NotNull(containingMessage, "containingMessage");
Requires.NotNullOrEmpty(data, "data");
Requires.NotNullOrEmpty(messagePartName, "messagePartName");
Contract.Ensures(Contract.Result() != null);
throw new System.NotImplementedException();
}
#endregion
}
}