?
Solved

Read Struct and enum definitions in C#

Posted on 2007-08-03
7
Medium Priority
?
412 Views
Last Modified: 2013-12-17
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?
0
Comment
Question by:Barbless
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Accepted Solution

by:
Tommie Nathaniel Carter, Jr., MBA earned 150 total points
ID: 19627425
The file is a class file? Or are you reading from a compiled assembly? In the either case I think what we want is to add the file/assembly to an existing project as either a reference (assembly) or an imported item to the project.
0
 

Author Comment

by:Barbless
ID: 19627648
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.
0
 
LVL 25

Assisted Solution

by:dstanley9
dstanley9 earned 225 total points
ID: 19627748
You can't define enums and structs from a file becuase they need to be defined at compile-time.  
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 4

Assisted Solution

by:Tommie Nathaniel Carter, Jr., MBA
Tommie Nathaniel Carter, Jr., MBA earned 150 total points
ID: 19627776
If you can see source code then you can compile the files and afterwards include them as references in your project.

There are classes etc. in this solution right? If so then build the files in a separate project  that you want to use and add them as refs in your current project.
0
 
LVL 25

Assisted Solution

by:dstanley9
dstanley9 earned 225 total points
ID: 19627812
Just to clarify, I assume you're talking about reading in the enum values and struct defs at run-time.  If so, you can't do that because they are defined at compile-time.  You could do it at compile-time by creating some sort of code-generation template using Codesmith or something, but any changes to the source files wouldn't be available until you rebuilt the project.
0
 

Author Comment

by:Barbless
ID: 19628499
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.
0
 
LVL 25

Assisted Solution

by:dstanley9
dstanley9 earned 225 total points
ID: 19628618
Yeah, I  think some sort of code gen is going to be your best bet.  There is no #include directive to add content from an outside file.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question