Reading a structure from a file stream?

Merrion

Well-known member
Joined
Sep 29, 2001
Messages
265
Location
Dublin, Ireland
User Rank
*Experts*
Any ideas how I might read a structure from a file stream? ideally Im looking for something that is like Marshal.PtrToStructure but instead of an unmanaged memory address I pass a file stream handle?
 
This sounds curiously close to a form of serialization. While there isnt anything in the BCLs that does what youre looking for there may very well be a different means of approaching this. Mind explaining a bit more?
 
I have a custom binary file (really boring accountancy stuff) that was written by a C++ program and I want to import it into a VB.Net prgram.

So - the file comes in and it has one header record, followed by a number of transaction records and each transaction record has sub transaction records. Each structure has a common header which is:
Code:
  TransactionRecordType As Int32
  TransactionRecordSize As Int32

Any thoughts - currently I have like:
Code:
Public Class TransactionHeaderRecord

  Private _RecordType As Int32
  Private _RecordSize As Int32

Public Sub New(ByVal InFile As BinaryStreamReader)

   _RecordType = InFile.ReadInt32
   _RecordSize = InFile.ReadInt32
  -- other fields go here...

End Sub

End Class

But that introduces a horrid maintenance problem if the record type has to be changed....
 
Back
Top