Class SerializationExtensions
Extension methods for serialization convenience.
Inheritance
Inherited Members
Namespace: Kephas.Serialization
Assembly: Kephas.Core.dll
Syntax
public static class SerializationExtensions
Methods
| Improve this Doc View SourceCreateOrUpdateSerializationContext<TMediaType>(IContextFactory, ISerializationContext, Action<ISerializationContext>)
Creates the serialization context or updates it with the serialization service and media type.
Declaration
public static ISerializationContext CreateOrUpdateSerializationContext<TMediaType>(this IContextFactory contextFactory, ISerializationContext context = null, Action<ISerializationContext> contextConfig = null)
where TMediaType : IMediaType
Parameters
Type | Name | Description |
---|---|---|
IContextFactory | contextFactory | The context factory. |
ISerializationContext | context | Optional. The serialization context. |
System.Action<ISerializationContext> | contextConfig | Optional. The context configuration. |
Returns
Type | Description |
---|---|
ISerializationContext | The new serialization context. |
Type Parameters
Name | Description |
---|---|
TMediaType | Type of the media type. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
CreateSerializationContext<TMediaType>(IContextFactory, Func<Object>)
Creates a new configured SerializationContext.
Declaration
public static SerializationContext CreateSerializationContext<TMediaType>(this IContextFactory contextFactory, Func<object> rootObjectFactory = null)
where TMediaType : IMediaType
Parameters
Type | Name | Description |
---|---|---|
IContextFactory | contextFactory | The context factory. |
System.Func<System.Object> | rootObjectFactory | Optional. The root object factory. |
Returns
Type | Description |
---|---|
SerializationContext | A configured SerializationContext. |
Type Parameters
Name | Description |
---|---|
TMediaType | Type of the media type. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when one or more arguments have unsupported or illegal values. |
CreateSerializationContext<TMediaType, TRootObject>(IContextFactory, Func<Object>)
Creates a new configured SerializationContext.
Declaration
public static SerializationContext CreateSerializationContext<TMediaType, TRootObject>(IContextFactory contextFactory, Func<object> rootObjectFactory = null)
where TMediaType : IMediaType
Parameters
Type | Name | Description |
---|---|---|
IContextFactory | contextFactory | The context factory. |
System.Func<System.Object> | rootObjectFactory | Optional. The root object factory. |
Returns
Type | Description |
---|---|
SerializationContext | A configured SerializationContext. |
Type Parameters
Name | Description |
---|---|
TMediaType | Type of the media type. |
TRootObject | Type of the root object. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when one or more arguments have unsupported or illegal values. |
Deserialize(ISerializer, TextReader, ISerializationContext)
Deserializes an object.
Declaration
public static object Deserialize(this ISerializer serializer, TextReader textReader, ISerializationContext context = null)
Parameters
Type | Name | Description |
---|---|---|
ISerializer | serializer | The serializer to act on. |
System.IO.TextReader | textReader | The System.IO.TextReader containing the serialized object. |
ISerializationContext | context | Optional. The context. |
Returns
Type | Description |
---|---|
System.Object | The deserialized object. |
Deserialize(ISerializer, String, ISerializationContext)
Deserializes an object.
Declaration
public static object Deserialize(this ISerializer serializer, string serializedObj, ISerializationContext context = null)
Parameters
Type | Name | Description |
---|---|---|
ISerializer | serializer | The serializer to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
Returns
Type | Description |
---|---|
System.Object | The deserialized object. |
Deserialize<TMediaType>(ISerializationService, String, ISerializationContext)
Deserializes the object from the provided format.
Declaration
public static object Deserialize<TMediaType>(this ISerializationService serializationService, string serializedObj, ISerializationContext context = null)
where TMediaType : IMediaType
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
Returns
Type | Description |
---|---|
System.Object | The deserialized object. |
Type Parameters
Name | Description |
---|---|
TMediaType | Type of the media type. |
Deserialize<TMediaType, TRootObject>(ISerializationService, String, ISerializationContext)
Deserializes the object from the provided format.
Declaration
public static TRootObject Deserialize<TMediaType, TRootObject>(this ISerializationService serializationService, string serializedObj, ISerializationContext context = null)
where TMediaType : IMediaType
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
Returns
Type | Description |
---|---|
TRootObject | The deserialized object. |
Type Parameters
Name | Description |
---|---|
TMediaType | Type of the media type. |
TRootObject | Type of the root object. |
DeserializeAsync(ISerializer, String, ISerializationContext, CancellationToken)
Deserialize an object asynchronously.
Declaration
public static Task<object> DeserializeAsync(this ISerializer serializer, string serializedObj, ISerializationContext context = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
ISerializer | serializer | The serializer to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | A Task promising the deserialized object. |
DeserializeAsync<TMediaType>(ISerializationService, String, ISerializationContext, CancellationToken)
Deserializes the object from the provided format asynchronously.
Declaration
public static Task<object> DeserializeAsync<TMediaType>(this ISerializationService serializationService, string serializedObj, ISerializationContext context = null, CancellationToken cancellationToken = default(CancellationToken))
where TMediaType : IMediaType
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | A Task promising the deserialized object. |
Type Parameters
Name | Description |
---|---|
TMediaType | Type of the media type. |
DeserializeAsync<TMediaType, TRootObject>(ISerializationService, String, ISerializationContext, CancellationToken)
Deserializes the object from the provided format asynchronously.
Declaration
public static Task<TRootObject> DeserializeAsync<TMediaType, TRootObject>(this ISerializationService serializationService, string serializedObj, ISerializationContext context = null, CancellationToken cancellationToken = default(CancellationToken))
where TMediaType : IMediaType
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TRootObject> | A Task promising the deserialized object. |
Type Parameters
Name | Description |
---|---|
TMediaType | Type of the media type. |
TRootObject | Type of the root object. |
JsonDeserialize(ISerializationService, String, ISerializationContext)
Deserializes the object from JSON.
Declaration
public static object JsonDeserialize(this ISerializationService serializationService, string serializedObj, ISerializationContext context = null)
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
Returns
Type | Description |
---|---|
System.Object | The deserialized object. |
JsonDeserialize<TRootObject>(ISerializationService, String, ISerializationContext)
Deserializes the object from JSON.
Declaration
public static TRootObject JsonDeserialize<TRootObject>(this ISerializationService serializationService, string serializedObj, ISerializationContext context = null)
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
Returns
Type | Description |
---|---|
TRootObject | The deserialized object. |
Type Parameters
Name | Description |
---|---|
TRootObject | Type of the root object. |
JsonDeserializeAsync(ISerializationService, String, ISerializationContext, CancellationToken)
Deserializes the object from JSON asynchronously.
Declaration
public static Task<object> JsonDeserializeAsync(this ISerializationService serializationService, string serializedObj, ISerializationContext context = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | A Task promising the deserialized object. |
JsonDeserializeAsync<TRootObject>(ISerializationService, String, ISerializationContext, CancellationToken)
Deserializes the object from JSON asynchronously.
Declaration
public static Task<TRootObject> JsonDeserializeAsync<TRootObject>(this ISerializationService serializationService, string serializedObj, ISerializationContext context = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TRootObject> | A Task promising the deserialized object. |
Type Parameters
Name | Description |
---|---|
TRootObject | Type of the root object. |
JsonSerialize(ISerializationService, Object, ISerializationContext)
Serializes the provided object as JSON.
Declaration
public static string JsonSerialize(this ISerializationService serializationService, object obj, ISerializationContext context = null)
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.Object | obj | The object. |
ISerializationContext | context | The context. |
Returns
Type | Description |
---|---|
System.String | The serialized object as a JSON string. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the MediaType is not JsonMediaType in the provided context. |
JsonSerializeAsync(ISerializationService, Object, ISerializationContext, CancellationToken)
Serializes the provided object as JSON asynchronously.
Declaration
public static Task<string> JsonSerializeAsync(this ISerializationService serializationService, object obj, ISerializationContext context = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.Object | obj | The object. |
ISerializationContext | context | The context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.String> | A Task promising the serialized object as a JSON string. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the MediaType is not JsonMediaType in the provided context. |
Serialize(ISerializer, Object, ISerializationContext)
Serializes the provided object.
Declaration
public static string Serialize(this ISerializer serializer, object obj, ISerializationContext context = null)
Parameters
Type | Name | Description |
---|---|---|
ISerializer | serializer | The serializer to act on. |
System.Object | obj | The object. |
ISerializationContext | context | The context. |
Returns
Type | Description |
---|---|
System.String | The serialized object as a string. |
Serialize(ISerializer, Object, TextWriter, ISerializationContext)
Serializes the provided object.
Declaration
public static void Serialize(this ISerializer serializer, object obj, TextWriter textWriter, ISerializationContext context = null)
Parameters
Type | Name | Description |
---|---|---|
ISerializer | serializer | The serializer to act on. |
System.Object | obj | The object. |
System.IO.TextWriter | textWriter | The System.IO.TextWriter used to write the object content. |
ISerializationContext | context | Optional. The context. |
Serialize<TMediaType>(ISerializationService, Object, ISerializationContext)
Serializes the provided object in the specified format.
Declaration
public static string Serialize<TMediaType>(this ISerializationService serializationService, object obj, ISerializationContext context = null)
where TMediaType : IMediaType
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.Object | obj | The object. |
ISerializationContext | context | The context. |
Returns
Type | Description |
---|---|
System.String | The serialized object as a string in the specified format. |
Type Parameters
Name | Description |
---|---|
TMediaType | Type of the media type. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the MediaType is mismatched in the provided context. |
SerializeAsync(ISerializer, Object, ISerializationContext, CancellationToken)
Serializes the provided object asynchronously.
Declaration
public static Task<string> SerializeAsync(this ISerializer serializer, object obj, ISerializationContext context = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
ISerializer | serializer | The serializer to act on. |
System.Object | obj | The object. |
ISerializationContext | context | The context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.String> | A Task promising the serialized object as a string. |
SerializeAsync<TMediaType>(ISerializationService, Object, ISerializationContext, CancellationToken)
Serializes the provided object in the specified format.
Declaration
public static Task<string> SerializeAsync<TMediaType>(this ISerializationService serializationService, object obj, ISerializationContext context = null, CancellationToken cancellationToken = default(CancellationToken))
where TMediaType : IMediaType
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.Object | obj | The object. |
ISerializationContext | context | The context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.String> | A Task promising the serialized object as a string. |
Type Parameters
Name | Description |
---|---|
TMediaType | Type of the media type. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the MediaType is mismatched in the provided context. |
XmlDeserialize(ISerializationService, String, ISerializationContext)
Deserializes the object from XML.
Declaration
public static object XmlDeserialize(this ISerializationService serializationService, string serializedObj, ISerializationContext context = null)
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
Returns
Type | Description |
---|---|
System.Object | The deserialized object. |
XmlDeserialize<TRootObject>(ISerializationService, String, ISerializationContext)
Deserializes the object from XML.
Declaration
public static TRootObject XmlDeserialize<TRootObject>(this ISerializationService serializationService, string serializedObj, ISerializationContext context = null)
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
Returns
Type | Description |
---|---|
TRootObject | The deserialized object. |
Type Parameters
Name | Description |
---|---|
TRootObject | Type of the root object. |
XmlDeserializeAsync(ISerializationService, String, ISerializationContext, CancellationToken)
Deserializes the object from XML asynchronously.
Declaration
public static Task<object> XmlDeserializeAsync(this ISerializationService serializationService, string serializedObj, ISerializationContext context = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | A Task promising the deserialized object. |
XmlDeserializeAsync<TRootObject>(ISerializationService, String, ISerializationContext, CancellationToken)
Deserializes the object from XML asynchronously.
Declaration
public static Task<TRootObject> XmlDeserializeAsync<TRootObject>(this ISerializationService serializationService, string serializedObj, ISerializationContext context = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.String | serializedObj | The serialized object. |
ISerializationContext | context | The context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TRootObject> | A Task promising the deserialized object. |
Type Parameters
Name | Description |
---|---|
TRootObject | Type of the root object. |
XmlSerialize(ISerializationService, Object, ISerializationContext)
Serializes the provided object as XML.
Declaration
public static string XmlSerialize(this ISerializationService serializationService, object obj, ISerializationContext context = null)
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.Object | obj | The object. |
ISerializationContext | context | The context. |
Returns
Type | Description |
---|---|
System.String | The serialized object as a XML string. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the MediaType is not XmlMediaType in the provided context. |
XmlSerializeAsync(ISerializationService, Object, ISerializationContext, CancellationToken)
Serializes the provided object as XML asynchronously.
Declaration
public static Task<string> XmlSerializeAsync(this ISerializationService serializationService, object obj, ISerializationContext context = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
ISerializationService | serializationService | The serializationService to act on. |
System.Object | obj | The object. |
ISerializationContext | context | The context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.String> | A Task promising the serialized object as a XML string. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the MediaType is not XmlMediaType in the provided context. |