-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
IPersistableModel.cs
36 lines (32 loc) · 1.79 KB
/
IPersistableModel.cs
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace System.ClientModel.Primitives;
/// <summary>
/// Allows an object to control its own writing and reading.
/// The format is determined by the implementer.
/// </summary>
/// <typeparam name="T">The type the model can be converted into.</typeparam>
public interface IPersistableModel<out T>
{
/// <summary>
/// Writes the model into a <see cref="BinaryData"/>.
/// </summary>
/// <param name="options">The <see cref="ModelReaderWriterOptions"/> to use.</param>
/// <returns>A binary representation of the written model.</returns>
/// <exception cref="FormatException">If the model does not support the requested <see cref="ModelReaderWriterOptions.Format"/>.</exception>
BinaryData Write(ModelReaderWriterOptions options);
/// <summary>
/// Converts the provided <see cref="BinaryData"/> into a model.
/// </summary>
/// <param name="data">The <see cref="BinaryData"/> to parse.</param>
/// <param name="options">The <see cref="ModelReaderWriterOptions"/> to use.</param>
/// <returns>A <typeparamref name="T"/> representation of the data.</returns>
/// <exception cref="FormatException">If the model does not support the requested <see cref="ModelReaderWriterOptions.Format"/>.</exception>
T Create(BinaryData data, ModelReaderWriterOptions options);
/// <summary>
/// Gets the data interchange format (JSON, Xml, etc) that the model uses when communicating with the service.
/// <param name="options">The <see cref="ModelReaderWriterOptions"/> to use.</param>
/// </summary>
/// <returns>The format that the model uses when communicating with the serivce.</returns>
string GetFormatFromOptions(ModelReaderWriterOptions options);
}