Does the Lookup class use enum, struct, public const, something else?

I am creating a search class, so a constant value will be used in all projects. The fact is that there are several solutions for creating such a thing. I could create one class with enumerations, structures or constants in it, or create one class for each “object”. I am wondering what would be the best solution.

At first I thought of doing something like this:

public static class Defines
    {
        public enum PAGELAYOUT_NAMES
        {
            STANDARD = "Standard"
        }
    }

But personally, I do not like to use strings in enumerations. Another option would be to use a structure that is even uglier if you see the code:

public static class Defines
    {
        public struct PAGELAYOUT_NAMES
        {
            public static string STANDAARD = "Standaard";
        }
    }

This looks a little better, but can be confusing if you have a lot of options:

public static class Defines
{
        public const string PAGELAYOUT_NAMES_STANDARD = "Standard";
}

When typing this post, I think it will be the best / clean option:

public static class PageLayout
{
    public const string STANDARD = "Standard";
}

? , , .

Edit , . , Int, DateTime . , , .

:

 internal class Base<T>
    {
        internal T Value{ get; private set;}
        internal Base(T value)
        {
            Value = value;
        }
    }
    public class PageLayout
    {
        public static string Standard { get { return new Base<string>("Standard").Value; } }
    }

, . , , , .

+5
4

, factory. . .

 public class PageLayout
    {
        private readonly string LayoutType;
        private PageLayout(string layoutType)
        {
          LayoutType = layoutType;
        }
        public static Standard {get {return new PageLayout("Standard");}}
    }

PageLayout.Standard

+2

, , , , .

XML ( , ), ( " " ).

node , "" . .

, : -

String s = Resources.PageLayoutNames.Standard;

, , , . , , - , ASP.NET, , , , .

, .


Edit:

, , , : " ?".

, ?

enum PageLayouts
{
  Standard,
  ExtraAwesome
}

, , . DescriptionAttribute

enum PageLayouts
{
   [Description("Standard")]
   Standard,
   [Description("Extra Awesome")]
   ExtraAwesome
}

DescriptionAttribute . , ...

+4

, Defines , .

0

public static class PageLayout 
{ 
    public const string STANDARD = "Standard"; 
} 

.

However, I create more classes than one: when I use many sessionvariables variables, I create (public static)

class SessionNames

And I really make a difference between wide soul constants and large project constants.

sometimes the constants for one project (for example, 20 placeholders in a PDF that you have to create) have nothing to do with other projects, so I do this as a project class, but when I have wide solution constants, I create a class in the same place where I add line extensions, etc.

0
source

All Articles