initial commit
Pulsar .NET 9.0 Windows Release / build (push) Canceled after 0s
Mirror to Codeberg and Gitea / mirror (push) Canceled after 0s

This commit is contained in:
i2p
2026-08-27 10:57:58 -06:00
commit 773d05f8f1
1038 changed files with 109261 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;
namespace Pulsar.Client.Helper
{
/// <summary>
/// Provides methods to serialize and deserialize JSON.
/// </summary>
public static class JsonHelper
{
/// <summary>
/// Serializes an object to the respectable JSON string.
/// </summary>
public static string Serialize<T>(T o)
{
var s = new DataContractJsonSerializer(typeof(T));
using (var ms = new MemoryStream())
{
s.WriteObject(ms, o);
return Encoding.UTF8.GetString(ms.ToArray());
}
}
/// <summary>
/// Deserializes a JSON string to the specified object.
/// </summary>
public static T Deserialize<T>(string json)
{
var s = new DataContractJsonSerializer(typeof(T));
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
return (T)s.ReadObject(ms);
}
}
/// <summary>
/// Deserializes a JSON stream to the specified object.
/// </summary>
public static T Deserialize<T>(Stream stream)
{
var s = new DataContractJsonSerializer(typeof(T));
return (T)s.ReadObject(stream);
}
}
}