Referencing enum by shorthand from .Master file

45 Views Asked by At

We have a structure roughly as below:

namespace a.b.c.d.e {
    Master file
    namespace f {
        Page file
        Enum Colours
        Enum Fruits
    }
}

The master file is made up of 3 files: .Master, .Master.cs & .Master.designer.cs.

Several functions within Page refer to Colours or Fruits. Within the .Master.cs file I have using a.b.c.d.e.f - this should mean that I can reference Colours & Fruits without fully referencing them. This works as expected in the .Master.cs file - however putting <%=Page.GetTitle(Colours.Red)%> in the .Master file does not work. It just says "The name 'Colours' does not exist in the current context". Instead I have to put <%=Page.GetTitle(a.b.c.d.e.f.Colours.Red)%>.

Where am I going wrong? If Colours.Red works fine in the .Master.cs file, surely it should work in the .Master file?

1

There are 1 best solutions below

0
Shiin Zu On

As per this question you can move the enum outside the namespace so you don't have to reference it in your code. Otherwise, you need to keep using the full qualified name of the enum.