CapyKit/Docs/api/CapyKit.Helpers.SerializationHelper.md

160 lines
4 KiB
Markdown

# <a id="CapyKit_Helpers_SerializationHelper"></a> Class SerializationHelper
Namespace: [CapyKit.Helpers](CapyKit.Helpers.md)
Assembly: CapyKit.dll
```csharp
public static class SerializationHelper
```
#### Inheritance
[object](https://learn.microsoft.com/dotnet/api/system.object) ←
[SerializationHelper](CapyKit.Helpers.SerializationHelper.md)
#### Inherited Members
[object.Equals\(object?\)](https://learn.microsoft.com/dotnet/api/system.object.equals\#system\-object\-equals\(system\-object\)),
[object.Equals\(object?, object?\)](https://learn.microsoft.com/dotnet/api/system.object.equals\#system\-object\-equals\(system\-object\-system\-object\)),
[object.GetHashCode\(\)](https://learn.microsoft.com/dotnet/api/system.object.gethashcode),
[object.GetType\(\)](https://learn.microsoft.com/dotnet/api/system.object.gettype),
[object.MemberwiseClone\(\)](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone),
[object.ReferenceEquals\(object?, object?\)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals),
[object.ToString\(\)](https://learn.microsoft.com/dotnet/api/system.object.tostring)
#### Extension Methods
[ObjectExtensions.UpdateProperties\(object, object\)](CapyKit.Extensions.ObjectExtensions.md\#CapyKit\_Extensions\_ObjectExtensions\_UpdateProperties\_System\_Object\_System\_Object\_)
## Methods
### <a id="CapyKit_Helpers_SerializationHelper_Deserialize__1_System_Byte___"></a> Deserialize<T\>\(byte\[\]\)
Deserializes an object to a given <code class="typeparamref">T</code> type.
```csharp
public static T Deserialize<T>(byte[] bytes)
```
#### Parameters
`bytes` [byte](https://learn.microsoft.com/dotnet/api/system.byte)\[\]
The byte array representing a <code class="typeparamref">T</code> object.
#### Returns
T
A <code class="typeparamref">T</code> object.
#### Type Parameters
`T`
Generic type parameter.
#### Exceptions
[FormatException](https://learn.microsoft.com/dotnet/api/system.formatexception)
Thrown when the format of the byte array is incorrect.
### <a id="CapyKit_Helpers_SerializationHelper_Deserialize__1_System_IO_Stream_"></a> Deserialize<T\>\(Stream\)
Deserializes an object to a given <code class="typeparamref">T</code> type.
```csharp
public static T Deserialize<T>(Stream stream)
```
#### Parameters
`stream` [Stream](https://learn.microsoft.com/dotnet/api/system.io.stream)
The steam.
#### Returns
T
A <code class="typeparamref">T</code> object.
#### Type Parameters
`T`
Generic type parameter.
#### Exceptions
[FormatException](https://learn.microsoft.com/dotnet/api/system.formatexception)
Thrown when the format of an input is incorrect.
### <a id="CapyKit_Helpers_SerializationHelper_Deserialize__1_System_String_"></a> Deserialize<T\>\(string\)
Deserializes a <code>JSON</code> encoded string to the given <code class="typeparamref">T</code>.
```csharp
public static T Deserialize<T>(string str)
```
#### Parameters
`str` [string](https://learn.microsoft.com/dotnet/api/system.string)
The <code>JSON</code> encoded string representing a <code class="typeparamref">T</code> object.
#### Returns
T
A <code class="typeparamref">T</code> object.
#### Type Parameters
`T`
Generic type parameter.
### <a id="CapyKit_Helpers_SerializationHelper_SerializeToBytes_System_Object_"></a> SerializeToBytes\(object\)
Serializes an object to a byte array.
```csharp
public static byte[] SerializeToBytes(object obj)
```
#### Parameters
`obj` [object](https://learn.microsoft.com/dotnet/api/system.object)
The object.
#### Returns
[byte](https://learn.microsoft.com/dotnet/api/system.byte)\[\]
A <code>JSON</code> encoded string.
### <a id="CapyKit_Helpers_SerializationHelper_SerializeToString_System_Object_"></a> SerializeToString\(object\)
Serializes an object to a <code>JSON</code> encoded string.
```csharp
public static string SerializeToString(object obj)
```
#### Parameters
`obj` [object](https://learn.microsoft.com/dotnet/api/system.object)
The object.
#### Returns
[string](https://learn.microsoft.com/dotnet/api/system.string)
A <code>JSON</code> encoded string.