Reputation: 1311
Here is my Enums.cs file that exists in a CPSLibrary Class Library:
namespace CPSLibrary.CPSEnums
{
public enum GoalType
{
STRATEGIC = 1,
TACTICAL = 2
}
}
In a code behind file within a web application that references CPSLibrary, I'm doing the following:
using CPSLibrary;
/* ... farther down the page ... */
proj.Goal == CPSLibrary.CPSEnums.GoalType.STRATEGIC;
That will work, but if I try to just reference it like CPSEnums.GoalType.STRATEGIC it won't. Additionally, if I add "using CPSLibary.CPSEnums" I can then reference it simply as GoalType.STRATEGIC.
What do I need to do to get this to recognize CPSEnums.GoalType.STRATEGIC ?
Oddly enough, other classes with the CPSLibrary Class Library can reference it as CPSEnums.GoalType.STRATEGIC just fine.
Bonus Question: in this example, does "CPSEnums" have a technical term? "Container" or something like that? Or is it just a part of the Namespace with no separate terminology?
TIA
Upvotes: 2
Views: 79
Reputation: 11445
Try this:
namespace CPSLibrary
{
public static class CPSEnums
{
public enum GoalType
{
STRATEGIC = 1,
TACTICAL = 2
}
}
}
var x = CPSEnums.GoalType.STRATEGIC;
Upvotes: 0
Reputation: 4636
Try changing your using statement to this...
using CPSEnums = CPSLibrary.CPSEnums;
This should allow you to reference it the way you want...
/* ... farther down the page ... */
proj.Goal == CPSEnums.GoalType.STRATEGIC;
Upvotes: 4
Reputation: 62246
Because your namespace name is CPSLibrary.CPSEnums
, so you can even write like:
using CPSLibrary.CPSEnums;
....
proj.Goal == GoalType.STRATEGIC; //NO NAMESPACE NAME
when you write using CPSLibrary
, you refer to the "parent" namespace of your defined one. This is perfectly valid. But to access your enum type, you need specify its namepsace, and its namespace is: CPSLibrary.CPSEnums
Upvotes: 0