In C#, I am using a library that defines an enum. I would like to allow consumers of my code (in a different assembly) to pass in an enum value as a parameter to one of my functions without having to reference the underlying library themselves.

Is there a way for me to expose the library's enumeration to my consumers?

3 Answers
3

You could define your own enum with the values you want to support, expose that to your consumers, and simply convert it to the library's enum before you call into it. Since enums are just numbers behind the scenes, it's easy to convert one enum's values to another's.

Within one minute you got three ups and an answer?
–
WillOct 22 '08 at 11:28

I was watching the question pretty closely, and I suspected this was the way I was going to have to go. So I gave him one of the ups and the answer. I don't think it's particularly mysterious that he got two other up votes.
–
brienOct 22 '08 at 11:35

The question didn't strike me as exciting, it was like 7:30 AM EST. Not accusing anybody of anything, but it was kinda weird to see that much action that fast.
–
WillOct 22 '08 at 11:48

Yeah, I'm always amazed that I can get quality responses to my stupid questions first thing in the morning. stackoverflow is great!
–
brienOct 22 '08 at 12:12

7:30AM EST is 12:30 midday in the UK and there are a lot of UK developers active on this site. Lunchtime seems as good a time as any to be checking this place.
–
Jeff YatesOct 22 '08 at 15:46

You can offer an overload that takes an int, describe which values are valid, then perform the cast yourself. Alternatively, you can offer a different enumeration in your library, then convert it before calling into the second library.