Upgraded projects to .NET 9.0 and added new projects `KBR.Cache`, `KBR.Shared`, and `KBR.Shared.Lite` to the solution. Introduced JWT authentication and OTP handling with new models, services, and configuration options. Updated database schema with new entities `Users` and `RefreshTokens`, and added migrations for schema changes. Implemented caching strategies using `AppDistributedCache` with support for in-memory, SQL Server, and Redis. Enhanced email handling with `MailHelpers` for domain replacement. Updated controllers, repositories, and configuration files to support new features.
77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
using Newtonsoft.Json;
|
|
|
|
namespace KBR.Shared.Lite.Extensions
|
|
{
|
|
public static class JsonExtensions
|
|
{
|
|
public static T? ToObject<T>(string value)
|
|
{
|
|
return JsonConvert.DeserializeObject<T>(value);
|
|
}
|
|
|
|
public static T? ToObjectSystemText<T>(string value)
|
|
{
|
|
return System.Text.Json.JsonSerializer.Deserialize<T>(value);
|
|
}
|
|
|
|
public static T? ToObject<T>(string value, Type destType)
|
|
{
|
|
var result = JsonConvert.DeserializeObject(value, destType);
|
|
|
|
if (result is null)
|
|
{
|
|
return default;
|
|
}
|
|
|
|
return (T)result;
|
|
}
|
|
|
|
public static object? ToObject(string value, Type destType)
|
|
{
|
|
return ToObject<object?>(value, destType);
|
|
}
|
|
|
|
public static T? ToObject<T>(string value, JsonConverter[] converters)
|
|
{
|
|
return JsonConvert.DeserializeObject<T>(value, converters);
|
|
}
|
|
|
|
public static T? ToObject<T>(string value, Type destType, JsonConverter[] converters)
|
|
{
|
|
var result = JsonConvert.DeserializeObject(value, destType, converters);
|
|
|
|
if (result is null)
|
|
{
|
|
return default;
|
|
}
|
|
|
|
return (T)result;
|
|
}
|
|
|
|
public static string ToJson<T>(T value)
|
|
{
|
|
return JsonConvert.SerializeObject(value);
|
|
}
|
|
|
|
public static string ToJsonSystemText<T>(T value)
|
|
{
|
|
return System.Text.Json.JsonSerializer.Serialize(value);
|
|
}
|
|
|
|
public static string ToJson<T>(T value, JsonSerializerSettings jsonSerializerSettings)
|
|
{
|
|
return JsonConvert.SerializeObject(value, jsonSerializerSettings);
|
|
}
|
|
|
|
public static byte[] ToUtf8Bytes(object obj)
|
|
{
|
|
return System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(obj);
|
|
}
|
|
|
|
public static T? ToObject<T>(byte[] utf8Json)
|
|
{
|
|
return System.Text.Json.JsonSerializer.Deserialize<T>(utf8Json);
|
|
}
|
|
}
|
|
}
|