OPCFoundation / UA-ModelCompiler

ModelCompiler converts XML files into C# and ANSI C
MIT License
151 stars 94 forks source link

Invalid enums generation #58

Closed trofimich closed 1 year ago

trofimich commented 4 years ago

I've declared the enum:

<opc:DataType SymbolicName="SiemensPlcType" BaseType="ua:Enumeration">
    <opc:Fields>
        <opc:Field Name="Common" Identifier="0" />
        <opc:Field Name="S7_1200" Identifier="1" />
        <opc:Field Name="S7_1500" Identifier="2" />
        <opc:Field Name="LOGO" Identifier="3" />
    </opc:Fields>
</opc:DataType>

Generated C# code is next:

public enum SiemensPlcType
{
    /// <summary>
    /// A description for the Common field.
    /// </summary>
    [EnumMember(Value = "Common_0")]
    Common = 0,

    /// <summary>
    /// A description for the S7_1200 field.
    /// </summary>
    [EnumMember(Value = "S7_1200")]
    S7_1200 = 1200,

    /// <summary>
    /// A description for the S7_1500 field.
    /// </summary>
    [EnumMember(Value = "S7_1500")]
    S7_1500 = 1500,

    /// <summary>
    /// A description for the LOGO field.
    /// </summary>
    [EnumMember(Value = "LOGO_3")]
    LOGO = 3,
}

Mistakes are in lines:

    S7_1200 = 1200,
    ...
    S7_1500 = 1500,

Should be:

    S7_1200 = 1,
    ...
    S7_1500 = 2,
opcfoundation-org commented 4 years ago

This is a known issue - using _ in enum names will cause issues with code generation.

opcfoundation-org commented 2 years ago

Added DisplayName to Parameter which is used to initialize EnumStrings or EnumValues.

See DemoModel.xml for an example. See https://github.com/OPCF-Members/UA-ModelCompiler for beta.

opcfoundation-org commented 1 year ago

Now part of public repository.