Initial commit: JDE Scoping Tool migration project
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
This commit is contained in:
Executable
+42
@@ -0,0 +1,42 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DataModel.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// JSON serialization helpers
|
||||
/// </summary>
|
||||
public static class JsonHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts parameter to JSON
|
||||
/// </summary>
|
||||
/// <param name="value">Value to serialize</param>
|
||||
/// <returns>Parameter value serialized in JSON format</returns>
|
||||
public static string ToJSON<T>(this T value)
|
||||
{
|
||||
return value == null ?
|
||||
"{}" :
|
||||
JsonConvert.SerializeObject(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses value from JSON
|
||||
/// </summary>
|
||||
/// <param name="json">JSON to parse</param>
|
||||
/// <returns>Parsed value</returns>
|
||||
public static T FromJSON<T>(string json)
|
||||
{
|
||||
T value = default;
|
||||
try
|
||||
{
|
||||
value = JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Do nothing
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user