AnotherReplayReader/IpAndPlayer.cs

45 lines
1.1 KiB
C#

using AnotherReplayReader.Utils;
using System.Text.Json.Serialization;
namespace AnotherReplayReader
{
public sealed class IpAndPlayer
{
public static string SimpleIPToString(uint ip)
{
return $"{ip / 256 / 256 / 256}.{ip / 256 / 256 % 256}.{ip / 256 % 256}.{ip % 256}";
}
[JsonPropertyName("IP")]
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public uint Ip
{
get => _ip;
set
{
_ip = value;
IpString = SimpleIPToString(_ip);
}
}
[JsonIgnore]
public string IpString { get; private set; } = "0.0.0.0";
[JsonPropertyName("ID")]
public string Id
{
get => _id;
set
{
_id = value;
_pinyin = _id.ToPinyin();
}
}
[JsonIgnore]
public string? PinyinId => _pinyin;
private uint _ip;
private string _id = string.Empty;
private string? _pinyin;
}
}