continuity/Wonderking/Game/Reader/GenericReaderExtensions.cs

26 lines
775 B
C#
Raw Permalink Normal View History

2024-02-07 16:40:36 +01:00
// Licensed to Timothy Schenk under the GNU AGPL Version 3 License.
2023-11-20 19:58:30 +01:00
using System.Text;
namespace Wonderking.Game.Reader;
public static class GenericReaderExtensions {
public static string ReadString(this BinaryReader reader, int length) {
2024-09-16 21:19:09 +02:00
var ret = Encoding.ASCII.GetString(reader.ReadBytes(length)).Replace("\0", "", StringComparison.Ordinal);
return ret;
}
public static T[] ReadArray<T>(this BinaryReader pReader, int pLength) where T : new() {
var array = new T[pLength];
for (var index = 0; index < pLength; ++index) {
array[index] = pReader.Read<T>();
}
return array;
}
public static T Read<T>(this BinaryReader br) where T : new() {
return BinaryReader<T>.Read(br);
}
}