简体   繁体   English

VB6 DLL的枚举值未出现在C#中

[英]Enum values from VB6 DLL do not appear in C#

We have a VB6 DLL which includes several enum definitions. 我们有一个VB6 DLL,其中包含几个枚举定义。 We have loaded the VB6 DLL as a reference in a C# project. 我们已将VB6 DLL加载为C#项目中的参考。

In the Visual Studio 2010 object browser, all the VB6 classes are visible, as are the enum names . 在Visual Studio 2010对象浏览器中,所有VB6类以及枚举名称都是可见的。 However, the enum values are not shown, and also are not listed when using intellisense within C# code. 但是,在C#代码中使用智能感知时,枚举未显示,也未列出。 However the enum name does come up from intellisense, as do all the class names and class methods, properties etc. that I have tried. 但是,枚举名称确实来自智能感知,就像我尝试过的所有类名称和类方法,属性等一样。 So only the values seem to be left out. 因此,似乎仅忽略了这些值。

If I click the enum name in a code window and select Go To Definition, I get something like this: 如果我在代码窗口中单击枚举名称,然后选择“转到定义”,则会得到以下内容:

namespace DLLName
{
    [Guid("3DD0C797-2BF0-4A7A-8E1E-83E3095CB3AE")]
    public enum EnumName
    {
    }
}

Which shows the same thing - enum exists with no values. 这说明了同样的事情-枚举不存在值。

So the question is - where did the enum values go, and is there something we can do to get them to show up? 因此,问题是- 枚举值到哪里去了,我们可以做些什么使它们显示出来吗?

Note - I could modify the VB6 DLL if necessary. 注-如果需要,我可以修改VB6 DLL。

Thanks 谢谢

The enum values had spaces in the value names in VB6, and this causes them to be omitted from the enum definition in C#. 枚举值在VB6中的值名称中有空格 ,这导致它们在C#的枚举定义中被省略。

In VB6, you can declare enum values which have names with spaces in them, using a special square bracket syntax. 在VB6中,可以使用特殊的方括号语法声明枚举值,这些枚举值的名称中带有空格。 Examples: 例子:

Public Enum TestEnumNoSpaces
    EnumA
    EnumB
    EnumC
End Enum

Public Enum TestEnumWithSpaces
    [Enum A]
    [Enum B]
    [Enum C]
End Enum

If you compile this to a DLL and load it as a reference in Visual Studio 2010, in the object browser both enums are visible. 如果将其编译为DLL并作为参考加载到Visual Studio 2010中,则在对象浏览器中,两个枚举都是可见的。 However, the enum values are not shown. 但是,枚举未显示。

Most of the enums in the DLL I am using have enums with spaces in the names. 我正在使用的DLL中的大多数枚举都有名称中带有空格的枚举。 This has been a common naming convention. 这是一个常见的命名约定。 But fortunately, there were a few which did not use this format and I noticed their values were showing up in C#. 但是幸运的是,有一些没有使用这种格式,我注意到它们的值显示在C#中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM