I am trying to convert COBOL code to C#. One of the greatest challenges in general is revolves around the fact that COBOL is a loosely typed language as compared to C#.
In COBOL you can define an I/O buffer to read and write to an external file as effectively a byte array (e.g. records being read and written may contain mixed data types - strings, integers, etc).
A program may read a 100 byte record into this buffer and no type checking takes place.
The program may then move this data to the equivalent of a C# structure with a single simple statement like:
MOVE IO-BUFFER TO MY-STRUCTURE.
What this effectively does in pick of the 100 byte IO-BUFFER and lay it into the structure from the beginning of the Structure without doing a member by member move. The reason this works in COBOL is that COBOL allocates and maintains fixed length areas in memory for each item in a structure and does not perform type checking when moving data into a variable. SO it effectively treats the structure as a byte array and simply moves one byte array to another. It is taken for granted that the data will always be in the correct format with fix length items that cause the move ot line up with the individual field types.
Any idea how to do this in C# without having to write a special routine for each move to break the IO buffer up and do a field by field move into a structure?
In COBOL you can define an I/O buffer to read and write to an external file as effectively a byte array (e.g. records being read and written may contain mixed data types - strings, integers, etc).
A program may read a 100 byte record into this buffer and no type checking takes place.
The program may then move this data to the equivalent of a C# structure with a single simple statement like:
MOVE IO-BUFFER TO MY-STRUCTURE.
What this effectively does in pick of the 100 byte IO-BUFFER and lay it into the structure from the beginning of the Structure without doing a member by member move. The reason this works in COBOL is that COBOL allocates and maintains fixed length areas in memory for each item in a structure and does not perform type checking when moving data into a variable. SO it effectively treats the structure as a byte array and simply moves one byte array to another. It is taken for granted that the data will always be in the correct format with fix length items that cause the move ot line up with the individual field types.
Any idea how to do this in C# without having to write a special routine for each move to break the IO buffer up and do a field by field move into a structure?