You've already forked CC-Framework.BriskGameServer
96 lines
2.1 KiB
C#
96 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
internal static class BriskValueReader
|
|
{
|
|
public static string GetString(Dictionary<string, object> data, string key)
|
|
{
|
|
if (!TryGetValue(data, key, out var value) || value == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return Convert.ToString(value);
|
|
}
|
|
|
|
public static bool GetBool(Dictionary<string, object> data, string key)
|
|
{
|
|
if (!TryGetValue(data, key, out var value) || value == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (value is bool boolValue)
|
|
{
|
|
return boolValue;
|
|
}
|
|
|
|
if (bool.TryParse(Convert.ToString(value), out var parsed))
|
|
{
|
|
return parsed;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static int GetInt(Dictionary<string, object> data, string key)
|
|
{
|
|
if (!TryGetValue(data, key, out var value) || value == null)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
try
|
|
{
|
|
return Convert.ToInt32(value);
|
|
}
|
|
catch
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public static long GetLong(Dictionary<string, object> data, string key)
|
|
{
|
|
if (!TryGetValue(data, key, out var value) || value == null)
|
|
{
|
|
return 0L;
|
|
}
|
|
|
|
try
|
|
{
|
|
return Convert.ToInt64(value);
|
|
}
|
|
catch
|
|
{
|
|
return 0L;
|
|
}
|
|
}
|
|
|
|
public static Dictionary<string, object> GetDictionary(Dictionary<string, object> data, string key)
|
|
{
|
|
if (!TryGetValue(data, key, out var value) || value == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return value as Dictionary<string, object>;
|
|
}
|
|
|
|
public static List<object> GetList(Dictionary<string, object> data, string key)
|
|
{
|
|
if (!TryGetValue(data, key, out var value) || value == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return value as List<object>;
|
|
}
|
|
|
|
public static bool TryGetValue(Dictionary<string, object> data, string key, out object value)
|
|
{
|
|
value = null;
|
|
return data != null && !string.IsNullOrWhiteSpace(key) && data.TryGetValue(key, out value);
|
|
}
|
|
}
|