I am trying to define a struct dynamically in C#, based on a given input file with a list of member names and types. For the sake of the question, assume the file has the following layout:
[Struct Name 1]
parameter1, type1, typical_value1
parameter2, type2
parameter3, type1
[Struct Name 2]
... etc
I have been reading through this post for some time now, and have not yet implemented it in C# -- my question is, can this be done? Furthermore, can it be done without using unsafe
?
The reason I originally wanted to stick with using a struct is because I'm going to be using it to serialize a byte[]
received via I/O, and the extension methods I have right now work perfectly for statically defined structs; however I would be open to rewriting it for a wrapper class to make it easier.
The idea is that I would have one of several files that can be selected as a parsing source, based on what the user knows to be connected via I/O. In other words, the file can be changed during runtime but only a single file can be selected at a time.