Lets say I have a Class Named DataChunk each data chunk class has a header, this header has some basic Information on what the DataChunk contains.
Based on the name that Header Contains I need to figure out what Parsing class should be created and then add it to a collection
This is a basic version of the class
VB Code:
Interface IParseable Sub Read(byref Reader as BinaryReader) Sub Write(byRef Writer as BinaryWriter) End Interface
VB Code:
Public Class DataChunk Implements IParsable Public Sub New(byRef Reader as BinaryReader) Read(Reader) End Sub Private _Header as ChunkHeader Public Sub Read(byRef Reader as BinaryReader) _Header = New ChunkHeader(Reader) ' End Sub 'Write sub here (but not really relevant) End Class
ChunkHeader also Implements IParseable.
basicly There are many different types of dataChunk's, the Header's name property is what should be used to decide what class should be used to continue parsing.
These data chunks need to be stored in a typed collection so I was thinking of Inheriting Declaring dataChunk as MustOverride...
eg..
VB Code:
Public Class DataChunk Implements IParsable Public Sub New(byRef Reader as BinaryReader) Read(Reader) End Sub Private _Header as ChunkHeader Public Sub Read(byRef Reader as BinaryReader) _Header = New ChunkHeader(Reader) ParseData(Reader) End Sub Public Sub Write(byRef Writer as BinaryWriter) _Header.Write(Writer) RenderData(Writer) End Sub Public MustOverride Sub ParseData(byRef Reader as BinaryReader) Public MustOverride Sub RenderData(byRef Writer as BinaryWriter) Public MustOverride Function CanParse(DataChunkName as String) End Class
but then how do I dynamicly create an instance of the proper class only knowing the DataChunkName





Reply With Quote