Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
QuestionExchange Powershell with C# Pin
JD8627-Apr-12 5:31
JD8627-Apr-12 5:31 
Questioninclude a file Pin
__John_27-Apr-12 4:37
__John_27-Apr-12 4:37 
AnswerRe: include a file Pin
__John_27-Apr-12 4:42
__John_27-Apr-12 4:42 
GeneralRe: include a file Pin
Dave Kreskowiak27-Apr-12 8:13
mveDave Kreskowiak27-Apr-12 8:13 
GeneralRe: include a file Pin
PIEBALDconsult27-Apr-12 8:29
mvePIEBALDconsult27-Apr-12 8:29 
JokeRe: include a file Pin
Big Daddy Farang27-Apr-12 10:05
Big Daddy Farang27-Apr-12 10:05 
AnswerRe: include a file Pin
VJ Reddy27-Apr-12 5:03
VJ Reddy27-Apr-12 5:03 
AnswerRe: include a file PinPopular
PIEBALDconsult27-Apr-12 5:32
mvePIEBALDconsult27-Apr-12 5:32 
Well... the quick and dirty way would be to pass it through a C pre-processor. However, you may want to limit the scope of what you do that way.

Without seeing what's actually in the header file and which parts you need, I'll show a simple example of what can be done:

Example.h
# define OPEN  1
# define CLOSE 2
# define READ  3
# define WRITE 4


Example.csi (choose an extension)
namespace Support
{
  public static class Command
  {
    public const int Open  = OPEN ;
    public const int Close = CLOSE ;
    public const int Read  = READ ;
    public const int Write = WRITE ;
  }

  // or

  public enum Command
  {
    Open  = OPEN
  ,
    Close = CLOSE
  ,
    Read  = READ
  ,
    Write = WRITE
  }
}


Pass them through a C pre-processor, this uses the Visual C/C++ one:
cl /nologo /C /EP /P /FIC:Example.h /FiExample.cs Example.csi

Results in:

Example.cs
namespace Support
{
  public static class Command
  {
    public const int Open  = 1 ;
    public const int Close = 2 ;
    public const int Read  = 3 ;
    public const int Write = 4 ;
  }

  // or

  public enum Command
  {
    Open  = 1
  ,
    Close = 2
  ,
    Read  = 3
  ,
    Write = 4
  }
}


You can then include this file in your project. If needed, you can have a pre-build step that performs the above pre-processing.

Notes:

0) The pre-C# file (csi) should not contain any directives
1) You should include a notice that it was generated
2) You could also set the file to read-only
3) Use a partial class if you want this to be part of a larger class so you don't pass the whole thing through the pre-processor


See also my Implanting Common Code in Unrelated Classes[^]
GeneralRe: include a file Pin
jschell28-Apr-12 7:39
jschell28-Apr-12 7:39 
QuestionC# Media Library Help ! Pin
O.Calderbank27-Apr-12 2:27
O.Calderbank27-Apr-12 2:27 
AnswerRe: C# Media Library Help ! Pin
Richard MacCutchan27-Apr-12 2:42
mveRichard MacCutchan27-Apr-12 2:42 
AnswerRe: C# Media Library Help ! Pin
Wes Aday27-Apr-12 10:03
professionalWes Aday27-Apr-12 10:03 
QuestionDocument opening/saving idiom Pin
Orjan Westin27-Apr-12 1:07
professionalOrjan Westin27-Apr-12 1:07 
AnswerRe: Document opening/saving idiom PinPopular
Pete O'Hanlon27-Apr-12 1:57
mvePete O'Hanlon27-Apr-12 1:57 
AnswerRe: Document opening/saving idiom Pin
PIEBALDconsult27-Apr-12 3:22
mvePIEBALDconsult27-Apr-12 3:22 
AnswerRe: Document opening/saving idiom Pin
Eddy Vluggen27-Apr-12 7:04
professionalEddy Vluggen27-Apr-12 7:04 
AnswerRe: Document opening/saving idiom Pin
OriginalGriff27-Apr-12 9:29
mveOriginalGriff27-Apr-12 9:29 
NewsExpand the text in the RichTextBox. Pin
nqs_vn27-Apr-12 0:10
nqs_vn27-Apr-12 0:10 
AnswerRe: Expand the text in the RichTextBox. Pin
VJ Reddy27-Apr-12 1:16
VJ Reddy27-Apr-12 1:16 
GeneralRe: Expand the text in the RichTextBox. Pin
nqs_vn27-Apr-12 16:40
nqs_vn27-Apr-12 16:40 
QuestionSave List with BinaryReader Pin
larsp77726-Apr-12 23:22
larsp77726-Apr-12 23:22 
AnswerRe: Save List with BinaryReader Pin
Wayne Gaylard26-Apr-12 23:44
professionalWayne Gaylard26-Apr-12 23:44 
QuestionWindow Service didn’t run when SQL Server is on Remote Database Pin
masterprogrammertech26-Apr-12 23:17
masterprogrammertech26-Apr-12 23:17 
AnswerRe: Window Service didn’t run when SQL Server is on Remote Database Pin
PIEBALDconsult27-Apr-12 3:24
mvePIEBALDconsult27-Apr-12 3:24 
AnswerRe: Window Service didn’t run when SQL Server is on Remote Database Pin
charlybones7-May-12 22:17
charlybones7-May-12 22:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.