Defining enum inside of enum?

  • Thread starter Thread starter Brett Romero
  • Start date Start date
B

Brett Romero

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
 
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
 
From the comments, I don't see a way to get the
webPageInfo.index.AbsoluteURL syntax.

Thanks,
Brett
 
Brett Romero said:
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.
 
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
 
Brett Romero said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top