Frage

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.

Keine korrekte Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top