コード例 #1
0
        public static BinaryVdf Parse(byte[] data, Type headerType = null)
        {
            if (headerType != null && !SupportedVersionMappings.ContainsKey(headerType))
            {
                throw new ArgumentException($"Unsupported header type: {headerType}", nameof(headerType));
            }

            var vdf = new BinaryVdf {
                _headerType = headerType
            };

            using (var reader = BufferUtilities.CreateReader(data))
                vdf.ParseFromBuffer(reader);
            return(vdf);
        }
コード例 #2
0
        public static LegacyGameStats Parse(byte[] data, string game)
        {
            if (!GameStatTypeMappings.ContainsKey(game))
            {
                throw new InvalidOperationException($"The statistics format \"{game}\" is not supported.");
            }

            // Reflection to instantiate with the type of gamestats here
            var type         = GameStatTypeMappings[game];
            var stats        = new LegacyGameStats();
            var statsGeneric = typeof(LegacyGameStats).GetMethod(nameof(ParseFromBuffer))?.MakeGenericMethod(type);

            if (statsGeneric == null)
            {
                return(null);
            }

            // Invoke the read and return our stats
            using (var reader = BufferUtilities.CreateReader(data))
                statsGeneric.Invoke(stats, new object[] { reader });
            return(stats);
        }