473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

enum defined in a linked .cs file

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
Nov 17 '05 #1
8 1687
So how exactly is the enum defined and are you trying to use it across
different projects and\or namespaces?

HTH

Ollie Riches

"Joe" <jb*******@noemail.noemail> wrote in message
news:Oj**************@TK2MSFTNGP14.phx.gbl...
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

Nov 17 '05 #2
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();
}

"Ollie Riches" <ol**********@phoneanalyser.net> wrote in message
news:ew**************@TK2MSFTNGP15.phx.gbl...
So how exactly is the enum defined and are you trying to use it across
different projects and\or namespaces?

HTH

Ollie Riches

"Joe" <jb*******@noemail.noemail> wrote in message
news:Oj**************@TK2MSFTNGP14.phx.gbl...
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


Nov 17 '05 #3
That looks perfectly fine, it shoudl compile ok

Ollie
"Joe" <jb*******@noemail.noemail> wrote in message
news:e%****************@TK2MSFTNGP14.phx.gbl...
// 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();
}

"Ollie Riches" <ol**********@phoneanalyser.net> wrote in message
news:ew**************@TK2MSFTNGP15.phx.gbl...
So how exactly is the enum defined and are you trying to use it across
different projects and\or namespaces?

HTH

Ollie Riches

"Joe" <jb*******@noemail.noemail> wrote in message
news:Oj**************@TK2MSFTNGP14.phx.gbl...
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



Nov 17 '05 #4
Joe
It compiles fine but I get a warning about enum whatever being defined in 2
locations.

"Ollie Riches" <ol**********@phoneanalyser.net> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
That looks perfectly fine, it shoudl compile ok

Ollie
"Joe" <jb*******@noemail.noemail> wrote in message
news:e%****************@TK2MSFTNGP14.phx.gbl...
// 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();
}

"Ollie Riches" <ol**********@phoneanalyser.net> wrote in message
news:ew**************@TK2MSFTNGP15.phx.gbl...
So how exactly is the enum defined and are you trying to use it across
different projects and\or namespaces?

HTH

Ollie Riches

"Joe" <jb*******@noemail.noemail> wrote in message
news:Oj**************@TK2MSFTNGP14.phx.gbl...
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



Nov 17 '05 #5
Joe <jb*******@noemail.noemail> wrote:
It compiles fine but I get a warning about enum whatever being defined in 2
locations.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
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

"Joe" <jb*******@noemail.noemail> wrote in message
news:eq**************@TK2MSFTNGP10.phx.gbl...
It compiles fine but I get a warning about enum whatever being defined in
2 locations.

"Ollie Riches" <ol**********@phoneanalyser.net> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
That looks perfectly fine, it shoudl compile ok

Ollie
"Joe" <jb*******@noemail.noemail> wrote in message
news:e%****************@TK2MSFTNGP14.phx.gbl...
// 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();
}

"Ollie Riches" <ol**********@phoneanalyser.net> wrote in message
news:ew**************@TK2MSFTNGP15.phx.gbl...
So how exactly is the enum defined and are you trying to use it across
different projects and\or namespaces?

HTH

Ollie Riches

"Joe" <jb*******@noemail.noemail> wrote in message
news:Oj**************@TK2MSFTNGP14.phx.gbl...
>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
>



Nov 17 '05 #7
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.

Nov 17 '05 #8
Joe
Thanks Derrick. I don't know why I didn't create a separate library to begin
with. I already have like ~15.

"Derrick" <de***********@hotmail.com> wrote in message
news:zd******************@news20.bellglobal.com...
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

"Joe" <jb*******@noemail.noemail> wrote in message
news:eq**************@TK2MSFTNGP10.phx.gbl...
It compiles fine but I get a warning about enum whatever being defined in
2 locations.

"Ollie Riches" <ol**********@phoneanalyser.net> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
That looks perfectly fine, it shoudl compile ok

Ollie
"Joe" <jb*******@noemail.noemail> wrote in message
news:e%****************@TK2MSFTNGP14.phx.gbl...
// 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();
}

"Ollie Riches" <ol**********@phoneanalyser.net> wrote in message
news:ew**************@TK2MSFTNGP15.phx.gbl...
> So how exactly is the enum defined and are you trying to use it across
> different projects and\or namespaces?
>
> HTH
>
> Ollie Riches
>
> "Joe" <jb*******@noemail.noemail> wrote in message
> news:Oj**************@TK2MSFTNGP14.phx.gbl...
>>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
>>
>
>



Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
0
by: zheng | last post by:
I create a OCX program with ATL project, and One parameter in the interface function is ENUM type, and I has defined the ENUM type in the interface, but compiled falid with MIDL2001, in the...
0
by: MikeS | last post by:
Hi, I'm running into a very annoying issue when trying to use an enum defined in a C header file within a Managed C++ application. Within the 'C' header file, there is an enum defined as ...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
3
by: Jens Müller | last post by:
I have a file here with several enums: #ifndef PLANARSEP_OPTIMIZE_H #define PLANARSEP_OPTIMIZE_H enum fund_cycle_behavior_t {PASS_MODE_FIRST, PASS_MODE_BEST, PASS_MODE_ALL};
12
by: Cmtk Software | last post by:
I'm trying to define an enum which will be used from unmanaged c++, C++/CLI managed c++ and from C#. I defined the following enum in a VS dll project set to be compiled with the /clr switch: ...
10
by: Charlie | last post by:
I tried to post this before and I apologize if I am repeating myself, but I do not see the post anywhere. But anyway, I have a file, data.c, where I define all of my global variables. I then...
12
by: Charlie | last post by:
I have a file, data.c, where I define all of my global variables. I then have a header file, data.h, which I include in every file in which I reference all of the variables defined in data.c. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.