Link to home
Start Free TrialLog in
Avatar of Barbless
Barbless

asked on

Read Struct and enum definitions in C#

Instead of manually writing these this info in the source file, I need to read it from a file.

Does anyone know what the syntax is?
ASKER CERTIFIED SOLUTION
Avatar of Tommie Nathaniel Carter, Jr., MBA
Tommie Nathaniel Carter, Jr., MBA
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Barbless
Barbless

ASKER

Not sure. Here's the sample source code:

namespace Engine
{
//-----------------------------------------------------
    public enum a
    {
       ...
    }
    public enum b
    {
       ...
    }
    [StructLayout(LayoutKind.Sequential)]
    public struct a
    {
       ...
    }
    [StructLayout(LayoutKind.Sequential)]
    public struct b
    {
       ...
    }
    ...
//-----------------------------------------------------
}

I want cut out the portion between the lines, save it to a file as is, and in its place the syntax to read the file back.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes I'm doing it at compile time.  What got this whole thing started is that I'll have a conversion utility that takes a C header file and converts all its structs and enums into a file that will replace the portion in between the dash lines, and of course the file will have to be read in.

Given all the difficulties, I guess the easiest way is to add hard-coded lines to the conversion util to write all the necessary using statements at the top, add namespace, etc, so that the converted file is a complete C# source file.

Thanks for your help.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial