//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. 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, new() { /// /// 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 message that contains the serialized value. Must not be nulll. /// The serialized form of the to deserialize. Must not be null or empty. /// The deserialized value. Never null. T Deserialize(IProtocolMessage containingMessage, string data); } /// /// 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 message that contains the serialized value. Must not be nulll. /// The serialized form of the to deserialize. Must not be null or empty. /// The deserialized value. Never null. T IDataBagFormatter.Deserialize(IProtocolMessage containingMessage, string data) { Requires.NotNull(containingMessage, "containingMessage"); Requires.NotNullOrEmpty(data, "data"); Contract.Ensures(Contract.Result() != null); throw new System.NotImplementedException(); } #endregion } }