Passing enums across boundaries

G

guy

VS2005

I have a solution containing (amongst others) a Business layer project and a
DataAccess layer project.

Within these two projects I have a Class DoStuff , the business layer
doStuff makes calls to the DataAccess layer DoStuff. some of these calls
involve passing an enum as a parameter.

This enum is meaningless outside these two classes. The only way I can see
to make it visible to these two classes but not any other classes is to
define it in each class and make it Private, casting it where needed. This
however is not very clean.

Anyone have another suggestion?

Guy
 
K

Kevin Spencer

Why does it have to be private?

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
G

guy

Well it could be Protected I suppose, but what I need to do is to make theis
enum visible to two and only two classes, which are in different projects.

I dont want other classes to be able to see this enum as it is similar to
another enum that has wide visibility. This could cause confusion to other
developers.

Guy
 
P

PvdG42

guy said:
Well it could be Protected I suppose, but what I need to do is to make
theis
enum visible to two and only two classes, which are in different projects.

I dont want other classes to be able to see this enum as it is similar to
another enum that has wide visibility. This could cause confusion to other
developers.

Guy

Unless your two classes are somehow related via inheritance, I doubt
"Protected" will do it.

From VS docs:
The protected keyword is a member access modifier. A protected member is
accessible from within the class in which it is declared, and from within
any class derived from the class that declared this member.

A protected member of a base class is accessible in a derived class only if
the access takes place through the derived class type.
 
K

Kevin Spencer

Well, you have a couple of choices:

1. Rename the enum and make it public.
2. Don't use an enum. Use integers instead.
3. Cast to and from integers.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
R

Registered User

Well, you have a couple of choices:

1. Rename the enum and make it public.
2. Don't use an enum. Use integers instead.
3. Cast to and from integers.

Would the visitor pattern be of use here?

regards
A.G.
 

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