Add Windows desktop version

This commit is contained in:
renato97
2025-12-17 19:20:55 +00:00
parent 93dbe0941e
commit 8921d7f2a6
36 changed files with 2760 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
using System.Text.Json;
namespace StreamPlayer.Desktop;
public static class JsonExtensions
{
public static string GetPropertyOrDefault(this JsonElement element, string propertyName)
{
if (element.ValueKind == JsonValueKind.Object && element.TryGetProperty(propertyName, out var property))
{
return property.ValueKind switch
{
JsonValueKind.String => property.GetString() ?? string.Empty,
JsonValueKind.Number => property.GetRawText(),
JsonValueKind.True => "true",
JsonValueKind.False => "false",
_ => property.GetRawText()
};
}
return string.Empty;
}
public static int GetPropertyOrDefaultInt(this JsonElement element, string propertyName, int fallback = 0)
{
if (element.ValueKind == JsonValueKind.Object && element.TryGetProperty(propertyName, out var property))
{
if (property.TryGetInt32(out var value))
{
return value;
}
}
return fallback;
}
public static long GetPropertyOrDefaultLong(this JsonElement element, string propertyName, long fallback = 0)
{
if (element.ValueKind == JsonValueKind.Object && element.TryGetProperty(propertyName, out var property))
{
if (property.TryGetInt64(out var value))
{
return value;
}
}
return fallback;
}
public static bool GetPropertyOrDefaultBool(this JsonElement element, string propertyName, bool fallback = false)
{
if (element.ValueKind == JsonValueKind.Object && element.TryGetProperty(propertyName, out var property))
{
if (property.ValueKind == JsonValueKind.True)
{
return true;
}
if (property.ValueKind == JsonValueKind.False)
{
return false;
}
}
return fallback;
}
}