471,325 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 webPageNameTitle
{index = "Home Sweet Home"}

enum webPageRelativePath
{index = "index.aspx"}

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

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

Now each webpage is grouped by a common index name within one enum.
WebPageInfo.index for the index.page or WebPageInfo.Contact 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 4112
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.com>
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:WebPageInfo
{
public static readonly string FileName = "index.ascx";
public static readonly string AbsoluteURL =
"www.abc.com/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:WebPageInfo
....

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.index.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:WebPageInfo
{
public static readonly string FileName = "index.ascx";
public static readonly string AbsoluteURL =
"www.abc.com/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:WebPageInfo
...

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.com/index.ascx",
"Home Sweet Home");

// etc

private WebPageInfo (string filename,
string absoluteUrl,
string pageTitle)
{
this.filename = filename;
this.absoluteUrl = 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.com>
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.com>
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Alex Feldman | last post: by
1 post views Thread by Chad | last post: by
5 posts views Thread by Sadeq | last post: by
21 posts views Thread by dllhell | last post: by
13 posts views Thread by toton | last post: by
4 posts views Thread by ice8595 | last post: by
5 posts views Thread by =?GB2312?B?17/HvyBaaHVvLCBRaWFuZw==?= | last post: by

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.