RiskyBusiness

I have converted an old VB6 library to Visual C# and expose many internal classes and functions to an Excel front end via COM Interop. I am however slightly confused how to correctly expose a public enum.

Consider my current C# code;

Code Snippet

[Guid("8243E064-6204-4413-A542-0A206511A1EE")]
public class Constants
{
// Error constants
public enum myErrors
{
bad,
worse,
terrible
}

}


In the Excel VBA I see the enum as;

Code Snippet

Constants.myErrors.myErrors_bad
Constants.myErrors.myErrors_worse
Constants.myErrors.myErrors_terrible


This is clearly not ideal. I'm aiming for myErrors.bad etc.

Can anyone assist



Re: Visual C# General Exposing C# enum through COM Interop

Wole Ogunremi

The enum doesn't have to be nested in the class. Just declaring the enum outside of the class should give you the accessibility you require.




Re: Visual C# General Exposing C# enum through COM Interop

RiskyBusiness

Thanks for the response and you are correct, it does not need to be nested within a class, but this does not solve my problem. Items are still references as myErrors.myErrors_worse etc.

It must be possible for COM to maintain the access structure of <enum_name>.<enum_val_name> instead of what I have just now <enum_name>.<enum_name>_<enum_val_name>

Special attribute required perhaps