开发者

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

开发者 https://www.devze.com 2023-02-20 04:14 出处:网络
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

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开发者_如何学Python constructor, which im trying to avoid, and they should be read-only.

Thanks.


Just declare them as consts - a const is implicitly a static as well:

public class DigitalOuputs
{
  public const string FLAGLEDCOOL ="BIT12032"
  ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消