I'm converting legacy C# code to Unity 2017, and I'm stuck on methods to read binary data to a large struct.
I have the following struct defined :
[StructLayout(LayoutKind.Sequential)]
struct Header
{
public readonly int Magic;
public readonly int Version;
public readonly int FieldA;
public readonly int FieldB;
// ...
}
and the following code from my legacy C# application :
using (var strm = new FileStream(mFileName, FileMode.Open))
{
var reader = new BinaryReader(strm);
mHeader = reader.Read<Header>(); // <-- error here
}
The error message is : The non-generic method 'BinaryReader.Read()' cannot be used with typed arguments
I guess that a workaround could be to use a bunch of reader.Read() calls, but the header struct is rather large and I'd like to find a way to use what looks like a good shortcut and keep the code simpler and smaller.
Read<T>()method is custom code. It has never been part of the framework. It's probably an extension method, and if so, just copy it.Extensions.cscontaining the Read method. Many thanks !!!