//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.Messaging { using System; using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Text; /// /// The interface that classes must implement to be serialized/deserialized /// as protocol or extension messages. /// [ContractClass(typeof(IMessageContract))] public interface IMessage { /// /// Gets the version of the protocol or extension this message is prepared to implement. /// /// /// Implementations of this interface should ensure that this property never returns null. /// Version Version { get; } /// /// Gets the extra, non-standard Protocol parameters included in the message. /// /// /// Implementations of this interface should ensure that this property never returns null. /// IDictionary ExtraData { get; } /// /// Checks the message state for conformity to the protocol specification /// and throws an exception if the message is invalid. /// /// /// Some messages have required fields, or combinations of fields that must relate to each other /// in specialized ways. After deserializing a message, this method checks the state of the /// message to see if it conforms to the protocol. /// Note that this property should not check signatures or perform any state checks /// outside this scope of this particular message. /// /// Thrown if the message is invalid. void EnsureValidMessage(); } /// /// Code contract for the interface. /// [ContractClassFor(typeof(IMessage))] internal abstract class IMessageContract : IMessage { /// /// Prevents a default instance of the class from being created. /// private IMessageContract() { } /// /// Gets the version of the protocol or extension this message is prepared to implement. /// Version IMessage.Version { get { Contract.Ensures(Contract.Result() != null); return default(Version); // dummy return } } /// /// Gets the extra, non-standard Protocol parameters included in the message. /// /// /// /// Implementations of this interface should ensure that this property never returns null. /// IDictionary IMessage.ExtraData { get { Contract.Ensures(Contract.Result>() != null); return default(IDictionary); } } /// /// Checks the message state for conformity to the protocol specification /// and throws an exception if the message is invalid. /// /// /// Some messages have required fields, or combinations of fields that must relate to each other /// in specialized ways. After deserializing a message, this method checks the state of the /// message to see if it conforms to the protocol. /// Note that this property should not check signatures or perform any state checks /// outside this scope of this particular message. /// /// Thrown if the message is invalid. void IMessage.EnsureValidMessage() { } } }