mk.helpers
Search Results for

    Show / Hide Table of Contents

    Class Serialization

    Provides methods for data serialization and deserialization using JSON and BSON formats.

    Inheritance
    object
    Serialization
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: mk.helpers
    Assembly: mk.helpers.dll
    Syntax
    public static class Serialization

    Methods

    Deserialize<T>(byte[], SerializationType)

    Deserializes the provided byte array into an object of the specified type using the specified serialization format.

    Declaration
    public static T Deserialize<T>(byte[] data, SerializationType type) where T : class
    Parameters
    Type Name Description
    byte[] data

    The byte array to be deserialized.

    SerializationType type

    The serialization format to use.

    Returns
    Type Description
    T

    The deserialized object of the specified type.

    Type Parameters
    Name Description
    T

    The type of the object to be deserialized.

    FromBsonBytes<T>(byte[])

    Converts a BSON byte array to an object of the specified type.

    Declaration
    public static T FromBsonBytes<T>(byte[] obj) where T : class
    Parameters
    Type Name Description
    byte[] obj

    The BSON byte array to be deserialized.

    Returns
    Type Description
    T

    The deserialized object of the specified type.

    Type Parameters
    Name Description
    T

    The type of the object to be deserialized from BSON.

    FromBson<T>(string)

    Converts a BSON string to an object of the specified type.

    Declaration
    public static T FromBson<T>(string value)
    Parameters
    Type Name Description
    string value

    The BSON string to be deserialized.

    Returns
    Type Description
    T

    The deserialized object of the specified type.

    Type Parameters
    Name Description
    T

    The type of the object to be deserialized from BSON.

    FromJsonBytes<T>(byte[])

    Converts a JSON byte array to an object of the specified type.

    Declaration
    public static T FromJsonBytes<T>(byte[] obj) where T : class
    Parameters
    Type Name Description
    byte[] obj

    The JSON byte array to be deserialized.

    Returns
    Type Description
    T

    The deserialized object of the specified type.

    Type Parameters
    Name Description
    T

    The type of the object to be deserialized from JSON.

    FromJson<T>(string)

    Converts a JSON string to an object of the specified type.

    Declaration
    public static T FromJson<T>(string obj)
    Parameters
    Type Name Description
    string obj

    The JSON string to be deserialized.

    Returns
    Type Description
    T

    The deserialized object of the specified type.

    Type Parameters
    Name Description
    T

    The type of the object to be deserialized from JSON.

    Serialize<T>(T, SerializationType)

    Serializes the provided data into a byte array using the specified serialization format.

    Declaration
    public static byte[] Serialize<T>(T data, SerializationType type) where T : class
    Parameters
    Type Name Description
    T data

    The data to be serialized.

    SerializationType type

    The serialization format to use.

    Returns
    Type Description
    byte[]

    The serialized data as a byte array.

    Type Parameters
    Name Description
    T

    The type of the data being serialized.

    SetEncoding(Encoding)

    Sets the encoding to be used for serialization and deserialization.

    Declaration
    public static void SetEncoding(Encoding encoding)
    Parameters
    Type Name Description
    Encoding encoding

    The encoding to be set. If null, the default encoding will be used.

    ToBsonBytes<T>(T)

    Converts an object to its BSON representation as a byte array.

    Declaration
    public static byte[] ToBsonBytes<T>(T value) where T : class
    Parameters
    Type Name Description
    T value

    The object to be converted.

    Returns
    Type Description
    byte[]

    The BSON representation of the object as a byte array.

    Type Parameters
    Name Description
    T

    The type of the object to be converted to BSON.

    ToBson<T>(T)

    Converts an object to its BSON representation as a string.

    Declaration
    public static string ToBson<T>(T value) where T : class
    Parameters
    Type Name Description
    T value

    The object to be converted.

    Returns
    Type Description
    string

    The BSON representation of the object as a string.

    Type Parameters
    Name Description
    T

    The type of the object to be converted to BSON.

    ToJsonBytes<T>(T)

    Converts an object to its JSON representation as a byte array.

    Declaration
    public static byte[] ToJsonBytes<T>(T value) where T : class
    Parameters
    Type Name Description
    T value

    The object to be converted.

    Returns
    Type Description
    byte[]

    The JSON representation of the object as a byte array.

    Type Parameters
    Name Description
    T

    The type of the object to be converted to JSON.

    ToJson<T>(T)

    Converts an object to its JSON representation.

    Declaration
    public static string ToJson<T>(T obj)
    Parameters
    Type Name Description
    T obj

    The object to be converted.

    Returns
    Type Description
    string

    The JSON representation of the object.

    Type Parameters
    Name Description
    T

    The type of the object to be converted to JSON.

    In this article
    Back to top mk.helpers - MIT License