Gforse
Gforse

Reputation: 373

Converting C++ #Define enum creation to vb.net

For a project i need to a Enum list writen in C++ converterd to en VB.net Enum list. So far everything is OK except for the #define enums that are in the C++ list. Here's what i whant to convert:

typedef enum
{
 #define EnumValue(a,b) a, b=a+255
 EnumValue(PARAM_Start,PARAM_END)
} ID;

As you can see this creates 255 enums values at runtime. How is this done in VB.net?

EDIT / SOLVED 30-09-2016
As mentioned below i made the wrong assumption by thinking it would create 255 enums, instead it creates just two enums however given PARAM_END an extra offset of 255. Meaning: if i have a three enums, the index of these enums are 0,1,3. Now if i want the index of ENUM_3 to begin at 10 i just add ENUM_2 + 8 this way ENUM_3 will start at index 10.

Thanks all for responding so fast and helping me out! :-)

Upvotes: 0

Views: 228

Answers (2)

Brandon
Brandon

Reputation: 4593

As mentioned in comments, I think your C++ will create only 2...

Could you use a T4 Text Template?:

Add TextTemplate.tt to your VB project and fill it with this code:

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ import namespace="System" #>
<#@ output extension=".vb" #>

Namespace MyNamespace

    Public Enum MyEnum
    <# 
    for (int i = 1; i < 256; i++)
    {
    #>
    Number<#= i #> = <#= i #>
    <# } #>
    End Enum

End Namespace

Build your solution and it'll generate the type for you.

Upvotes: 0

Dave Doknjas
Dave Doknjas

Reputation: 6542

The VB equivalent is:

Public Enum ID
 PARAM_Start
 PARAM_END=PARAM_Start+255
End Enum

Not 255 values as you stated, but just 2.

Upvotes: 1

Related Questions