Domanda

Sto convertendo un'applicazione da C ++ a C#. L'applicazione C ++ ha un file definisce .h con oltre 500 direttive #define. Vorrei rappresentare questi dati in un file Definition.cs. Qual è il modo migliore per farlo?

Un esempio di definisce:

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

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

I #Defines sono raggruppati, quindi questo mi fa pensare di usare proprietà, come ad esempio:

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; }
    ...
}

Anche se dovrei impostare il valore predefinito in un costruttore, che sto cercando di evitare, e dovrebbero essere di sola lettura.

Grazie.

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top