mirror of
https://github.com/yawaflua/SPWorlds.git
synced 2025-12-10 04:29:35 +02:00
Add project files.
This commit is contained in:
23
Utils/Deserialization.cs
Normal file
23
Utils/Deserialization.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace SPWorldsApi.Utils
|
||||
{
|
||||
internal static class Deserialization
|
||||
{
|
||||
public static TClass Deserialize<TClass>(this string body) where TClass : class
|
||||
{
|
||||
TClass? objectToReturn = JsonSerializer.Deserialize<TClass>(body);
|
||||
if (objectToReturn == null)
|
||||
throw new Exception($"Error with deserializing object");
|
||||
else
|
||||
return objectToReturn;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user