enum defined in a linked .cs file

J

Joe

I have a .cs file which is linked to several other projects. All my classes
in this file are defined as internal. I would like to have an enum defined
as well in the namespace but I get an error from one project that the
accessibility of the enum is less (public) than that of a method which
returns that's type.

What is the best way to define this enum without getting duplicate define
warnings or this error of less accessibility?

Thanks,
Joe
 
O

Ollie Riches

So how exactly is the enum defined and are you trying to use it across
different projects and\or namespaces?

HTH

Ollie Riches
 
J

Joe

// In linked .cs
namespace something
{
public enum whatever {abc, def,};
}

// project A
public class ProjectA
{
public something.whatever GetEnum()
{
return something.whatever.abc;
}
}

// project B
private void CallProjectAClass()
{
ProjectA a = new ProjectA();
a.GetEnum();
}
 
J

Joe

It compiles fine but I get a warning about enum whatever being defined in 2
locations.
 
D

Derrick

If I understand correctly, you have 2 projects, and a common c# file that
you have included in both projects. This might compile OK, but at runtime I
can see there being a conflict, since both assemblies contain a definition
for "Something.Whatever". Even more problems could result if you had the
enum declared as internal, since internal essentially means "public, but
only inside this assembly".

Instead of including the c# file in both projects, create a 3rd shared
library projcet (say, common.dll) , and add a reference to that in the other
two projects, or more projects if need be. Your common enum - and any other
common classes - would go in there. That way, Project A and Project B would
be referencing the same definition for "Something.Whatever".

Hope that makes sense!

Derrick
 
J

Jeffrey Tan[MSFT]

Hi Joe,

Does Derrick's reply make sense to you? To use a shared library dll, we
have to expose the classes in the assembly as public, not internal, or the
outside assembly can not use it. If you have any concern, please feel free
to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Joe

Thanks Derrick. I don't know why I didn't create a separate library to begin
with. I already have like ~15.
 

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