blob: fd1c15d3953c22433664ec5d4e74756b1e4c1761 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
//-----------------------------------------------------------------------
// <copyright file="IDataBagFormatter.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Messaging {
using System;
using System.Diagnostics.Contracts;
/// <summary>
/// A serializer for <see cref="DataBag"/>-derived types
/// </summary>
/// <typeparam name="T">The DataBag-derived type that is to be serialized/deserialized.</typeparam>
[ContractClass(typeof(IDataBagFormatterContract<>))]
internal interface IDataBagFormatter<T> where T : DataBag, new() {
/// <summary>
/// Serializes the specified message.
/// </summary>
/// <param name="message">The message to serialize. Must not be null.</param>
/// <returns>A non-null, non-empty value.</returns>
string Serialize(T message);
/// <summary>
/// Deserializes a <see cref="DataBag"/>.
/// </summary>
/// <param name="containingMessage">The message that contains the <see cref="DataBag"/> serialized value. Must not be nulll.</param>
/// <param name="data">The serialized form of the <see cref="DataBag"/> to deserialize. Must not be null or empty.</param>
/// <returns>The deserialized value. Never null.</returns>
T Deserialize(IProtocolMessage containingMessage, string data);
}
/// <summary>
/// Contract class for the IDataBagFormatter interface.
/// </summary>
/// <typeparam name="T">The type of DataBag to serialize.</typeparam>
[ContractClassFor(typeof(IDataBagFormatter<>))]
internal abstract class IDataBagFormatterContract<T> : IDataBagFormatter<T> where T : DataBag, new() {
/// <summary>
/// Prevents a default instance of the <see cref="IDataBagFormatterContract<T>"/> class from being created.
/// </summary>
private IDataBagFormatterContract() {
}
#region IDataBagFormatter<T> Members
/// <summary>
/// Serializes the specified message.
/// </summary>
/// <param name="message">The message to serialize. Must not be null.</param>
/// <returns>A non-null, non-empty value.</returns>
string IDataBagFormatter<T>.Serialize(T message) {
Requires.NotNull(message, "message");
Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<string>()));
throw new System.NotImplementedException();
}
/// <summary>
/// Deserializes a <see cref="DataBag"/>.
/// </summary>
/// <param name="containingMessage">The message that contains the <see cref="DataBag"/> serialized value. Must not be nulll.</param>
/// <param name="data">The serialized form of the <see cref="DataBag"/> to deserialize. Must not be null or empty.</param>
/// <returns>The deserialized value. Never null.</returns>
T IDataBagFormatter<T>.Deserialize(IProtocolMessage containingMessage, string data) {
Requires.NotNull(containingMessage, "containingMessage");
Requires.NotNullOrEmpty(data, "data");
Contract.Ensures(Contract.Result<T>() != null);
throw new System.NotImplementedException();
}
#endregion
}
}
|