inline copies of enums

S

Sergio Trejo

Is it possible to make an inline copy in CSharp? I want to maintain a
single enumeration but make a copy of the members in a separate
enumeration.

I have an enumeration defined in a certain namespace:

namespace Graphing.Core
{
public enum EnumColors
{
Red = 1,
...
}
}

For organisational purposes I would like to introduce a separate
namespace that includes all the types that are intended for
interoperability. In this namespace I need a "mirror" of my original
enumeration but with a different name (to maintain our tlb naming
conventions). The enumeration members are exactly the same:

namespace GraphingInterop.Core
{
[System.Runtime.InteropServices.ComVisible(true)]
public enum EnumGraphColors
{
Red = 1,
...
}
}

I can not find any means in the language to achieve this unless we
maintain two copies of the enumeration. Does anybody have any
suggestions?
 
P

Peter Duniho

[...]
I can not find any means in the language to achieve this unless we
maintain two copies of the enumeration. Does anybody have any
suggestions?

I don't know enough about the interop issues to advise you specifically.
But generally speaking, no...C# doesn't have, for example, include files
or other ways of incorporating the same text in two or more places.

My first thought would be that surely there's some way to use the interop
namespace in your regular code. If so, I would think that would be a
better approach. Another alternative, albeit one likely to be very messy,
would be to create a standalone tool that generates the assembly in which
the non-interop type is declared automatically based on the interop type,
or vice a versa (using reflection to inspect the source type and the
built-in code generation to create the output).

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top