tags:

views:

55

answers:

2

I have my enum, which I don't want to share between layers.

So I was thinking wrapping it up would be neat.

But how ? There are many items, manualy writing down all items isn't a solution. Also the enum is getting generated.

I'd like to keep the intelisense.

+3  A: 

Well, you can cast to/from int (or the defined underlying type, which defaults to int), but this is brittle; it doesn't protect you when somebody removes an entry causing them to be re-numbered, or changes the meaning of 7 from Blah.TrivialDetail to Blah.CriticalFail.

If you want intellisense, all parties are going to need to know something about the numbers, so IMO you might just as well share the enum via some common assembly.

Marc Gravell
A: 

Well one way (not so elegant) is to create another enum in the assembly that can be shared. You need to create some build action to clone the generated enum from data assembly to new sharable enum. If generated enum is in a separate file then simple file copy (with change in namespace) as post-build event to DAL project or Pre-Build event in shared assembly project would do the trick. If the generated file contains some other stuff then you need to do some text processing in your favorite language (powershell, c#) to extract enumeration definition.

VinayC