diff --git a/SteamKit2/SteamKit2/Util/KeyValuePairExtensions.cs b/SteamKit2/SteamKit2/Util/KeyValuePairExtensions.cs deleted file mode 100644 index 4227cadc7..000000000 --- a/SteamKit2/SteamKit2/Util/KeyValuePairExtensions.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; - -namespace SteamKit2 -{ - static class KeyValuePairExtensions - { - public static void Deconstruct(this KeyValuePair kvp, out TKey key, out TValue value) - { - key = kvp.Key; - value = kvp.Value; - } - } -} diff --git a/SteamKit2/SteamKit2/Util/Utils.cs b/SteamKit2/SteamKit2/Util/Utils.cs index 6145971b7..e85481e28 100644 --- a/SteamKit2/SteamKit2/Util/Utils.cs +++ b/SteamKit2/SteamKit2/Util/Utils.cs @@ -21,9 +21,7 @@ static class Utils { public static string EncodeHexString(byte[] input) { - return input.Aggregate(new StringBuilder(), - (sb, v) => sb.Append(v.ToString("x2")) - ).ToString(); + return Convert.ToHexString(input).ToLower(); } [return: NotNullIfNotNull( nameof( hex ) )] @@ -32,13 +30,7 @@ public static string EncodeHexString(byte[] input) if (hex == null) return null; - int chars = hex.Length; - byte[] bytes = new byte[chars / 2]; - - for (int i = 0; i < chars; i += 2) - bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16); - - return bytes; + return Convert.FromHexString( hex ); } public static EOSType GetOSType() @@ -165,8 +157,7 @@ public static class DateUtils /// DateTime representation public static DateTime DateTimeFromUnixTime(ulong unixTime) { - DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); - return origin.AddSeconds(unixTime); + return DateTimeOffset.FromUnixTimeSeconds( (long)unixTime ).DateTime; } /// /// Converts a given DateTime into a unix timestamp representing seconds since the unix epoch. @@ -175,8 +166,7 @@ public static DateTime DateTimeFromUnixTime(ulong unixTime) /// 64-bit wide representation public static ulong DateTimeToUnixTime(DateTime time) { - DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); - return (ulong)(time - origin).TotalSeconds; + return (ulong)new DateTimeOffset( time ).ToUnixTimeSeconds(); } }