473,581 Members | 2,877 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 4245
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
1852
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
1116
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
1320
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
1642
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,...
21
2161
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
18095
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
1932
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...
8
8523
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
13476
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
7882
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...
0
7808
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8157
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. ...
0
8181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6564
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...
1
5683
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3809
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...
1
2309
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
1
1410
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.