473,699 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Defining enum inside of enum?

I'd like to create one enum that holds webpage name values and
corresponding URL values. For example:

enum webPageFileName
{index = "index.aspx "}

enum webPageName
{index = "index"}

enum webPageNameTitl e
{index = "Home Sweet Home"}

enum webPageRelative Path
{index = "index.aspx "}

enum webPageNameAbso luteURL
{index = "http://www.abc.com/index.aspx"}

But instead of referencing seperate enums, I could reference something
similar to this:
webPageInfo.ind ex.FileName
webPageInfo.ind ex.PageName
webPageInfo.ind ex.Title
webPageInfo.ind ex.RelativePath
webPageInfo.ind ex.AbsoluteURL

Now each webpage is grouped by a common index name within one enum.
WebPageInfo.ind ex for the index.page or WebPageInfo.Con tact for the
contact page. It's easy enough to get all the page info in one place
at that point.

This probably can't be done with an enum but needs a static class.
Suggestions?

Thanks,
Brett

Jan 16 '06 #1
6 4247
Brett Romero <ac*****@cygen. com> wrote:
I'd like to create one enum that holds webpage name values and
corresponding URL values.


It sounds like you want proper OO enums. See
http://msmvps.com/blogs/jon.skeet/ar...classenum.aspx
for my suggestions.

Unfortunately, they don't exist in C#. However, there are some comments
which would give you workarounds to give a similar effect, without the
language support.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 16 '06 #2
>From the comments on that page, here's the closest I can get:

public abstract class WebPageInfo
{

private WebPageInfo()
{
}

public class Index:WebPageIn fo
{
public static readonly string FileName = "index.ascx ";
public static readonly string AbsoluteURL =
"www.abc.co m/index.ascx";
public static readonly string PageTitle= "Home Sweet Home";
}
}

For every page involved, I'll need to create the above structure:

public class somePageName:We bPageInfo
....

which isn't so bad since most of the information isn't unique. Just
copy/paste and fill in the needed changes.

Brett

Jan 16 '06 #3
>From the comments, I don't see a way to get the
webPageInfo.ind ex.AbsoluteURL syntax.

Thanks,
Brett

Jan 16 '06 #4
Brett Romero <ac*****@cygen. com> wrote:
From the comments on that page, here's the closest I can get:


public abstract class WebPageInfo
{

private WebPageInfo()
{
}

public class Index:WebPageIn fo
{
public static readonly string FileName = "index.ascx ";
public static readonly string AbsoluteURL =
"www.abc.co m/index.ascx";
public static readonly string PageTitle= "Home Sweet Home";
}
}

For every page involved, I'll need to create the above structure:

public class somePageName:We bPageInfo
...

which isn't so bad since most of the information isn't unique. Just
copy/paste and fill in the needed changes.


I'd do it slightly differently. In this case, I'd just have:

public class WebPageInfo
{
public static readonly WebPageInfo Index =
new WebPageInfo ("index.ascx ",
"www.abc.co m/index.ascx",
"Home Sweet Home");

// etc

private WebPageInfo (string filename,
string absoluteUrl,
string pageTitle)
{
this.filename = filename;
this.absoluteUr l = absoluteUrl;
this.pageTitle = pageTitle;
}

public string Filename
{
get { return filename; }
}

// etc
}

The use of derived classes would really be if you wanted to override
method behaviour.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 17 '06 #5
Very good. Thanks. I can take the inheritance off of my technique.
It works just as well since I don't need inheritance.

Your technique creates an object for each page. I don't need objects.
However, yours does scale better and ends up with much less code. Is
there any disadvantage to creating all of these objects vs. somehow
staying completely static?

Thanks,
Brett

Jan 17 '06 #6
Brett Romero <ac*****@cygen. com> wrote:
Very good. Thanks. I can take the inheritance off of my technique.
It works just as well since I don't need inheritance.

Your technique creates an object for each page. I don't need objects.
However, yours does scale better and ends up with much less code. Is
there any disadvantage to creating all of these objects vs. somehow
staying completely static?


Not really - it's not like there are many of them, or that they get
created more than once.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 17 '06 #7

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

Similar topics

2
1865
by: Alex Feldman | last post by:
Which of the following is better? Defining an enum type inside a class as a nested type, or in the the namespace? An example of nested type enumerated type would be: public Class Product Public Enum Status psNormal psCharged End Enum
1
1118
by: Chad | last post by:
I'd like to define a set of enums that must be a subset of other enums. Something like this: Public Enum AllErrorNumbers As Integer Error1 = 1 Error2 = 2 Error3 = 3 End Enum Public Enum ErrorsForThisScreen As AllErrorNumbers Error1 = 1 Error2 = 2
11
1325
by: | last post by:
Is it possible to define a variable in a block in order to make it invisible outside that block? For example, in C I can write { int a .... } then a will only be available inside the curley brackets
5
1644
by: Sadeq | last post by:
Enums are useful when we want to constrain the user to choose from a specified number of predifined valuse. But they only accept integral types as their underlying type. I encountered a case in which I have to constrain the use to choose from a specified number of predifined int arrays. For example: readonly int choice1 ={ 1, 2, 840, 113549, 1, 1, 2 }; readonly int choice2 ={ 1, 2, 840, 113549, 1, 1, 4 }; readonly int choice3 ={ 1, 2,...
21
2164
by: dllhell | last post by:
hi all, I have a problem with creating proc with a enum as a param. I wish to pass an enumeration in proc in which one I intend to do some operations with enumeration, but I don't know which one enumeration I'll pass. so... I have tried with: string SomeResult (enum** _enum) { }
13
18134
by: toton | last post by:
Hi, I have some enum (enumeration ) defined in some namespace, not inside class. How to use the enum constant's in some other namespace without using the whole namespace. To say in little detail, the enum is declared as, namespace test{ enum MyEnum{ VALUE1,VALUE2 };
4
1937
by: ice8595 | last post by:
Hi there, I'm fairly new at this, and I am having a bit of trouble wrapping my head around some concepts of enum for a project. So any help would be greatly appreciated. Essentially I'm writing a program where i will have an enum in one of my classes. When the program is used, the user will define what actually goes inside the enum. So for example what I mean is if the class is WorkDay....and the user defines what days of the weeks he or...
8
8542
by: benn | last post by:
Here's the setup... Defines.h file contains: enum DAY { monday, tueday }; DayFunctions.h contains prototype: void printIsMonday ( enum DAY currentDay); DayFunctions.c contains:
5
13494
by: =?GB2312?B?17/HvyBaaHVvLCBRaWFuZw==?= | last post by:
Hi, I would like to have someone comments on what's the best practice defining error codes in C. Here's what I think: solution A: using enum pros: type safe. better for debug (some debugger will show the name not only the value) cons: enum can not be forward declared which makes all error codes
0
8686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9173
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7748
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5872
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.