What is the best practice for porting #defines from .h file to a C# application?

StackOverflow https://stackoverflow.com/questions/5426289

  •  11-11-2019
  •  | 
  •  

سؤال

I am converting an application from C++ to C#. The C++ application has a defines file .h with over 500 #define directives. I would like to represent this data in a Definition.cs file. What is the best way to do this?

An example of the defines:

//Digital ouputs
#define FLAGLEDCOOL             "BIT12032"
#define FLAGLEDLASERINTLK       "BIT12036"
#define FLAGLEDLASERSTANBDY     "BIT12038"
...

//Digital inputs
#define FLAGSTATUSINTLKRELAY    "BIT11535"
#define FLAGSTATUSEMERGRELAY    "BIT11533"
#define FLAGSTATUSKVMRELAY      "BIT11531"
...

The #defines are grouped so this make me think of using properties, such as:

public class DigitalOuputs
{
    public static string FLAGLEDCOOL { get; }
    public static string FLAGLEDLASERINTLK { get; }
    public static string FLAGLEDLASERSTANBDY { get; }
    ...
}

public class DigitalInputs
{
    public static string FLAGSTATUSINTLKRELAY { get; }
    public static string FLAGSTATUSEMERGRELAY { get; }
    public static string FLAGSTATUSKVMRELAY { get; }
    ...
}

Although I would have to set the default value in a constructor, which im trying to avoid, and they should be read-only.

Thanks.

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top