Access to an enumeration in another namespace

I am using C # in VS2005. I have a class library that contains several enumerations common to a number of different projects. When accessing one of these enumerations, I need to specify the entire namespace path to the enumeration, even if I declared the "using" directive for the namespace containing the enumeration.

For example, I have the following enumeration:

namespace Company.General.Project1
{
   public static class Rainbow
   {
    [Flags]
    public enum Colours
    {
      Red,
      Blue,
      Orange
    }
  }
}

Then in another project I have:

using Company.General.Project1;

namespace Company.SpecialProject.Processing
{
  public class MixingPallette
  {
    int myValue = Company.General.Project1.Colours.Red;
  }
}

Despite the fact that I have a 'Using' directive that references a project that contains an enumeration class, I still have to write enum longhand. Why can't I do the following ...

using Company.General.Project1;

namespace Company.SpecialProject.Processing
{
  public class MixingPallette
  {
    int myValue = Colours.Red;
  }
}
+3
source share
2

- . , "" ,

int myValue = (int) Company.General.Project1.Rainbow.Colours.Red;

( Rainbow, enum int.)

:

namespace Company.General.Project1
{
    [Flags]
    public enum Colours
    {
        Red,
        Blue,
        Orange
    }
}

:

using Company.General.Project1;

...

Colours x = Colours.Red;
int y = (int) Colours.Red;

( , [Flags] , , 1, 2, 4, 8...)


EDIT: , Colours.Red .. , :

Rainbow.Colours x = Rainbow.Colours.Red;
int y = (int) Rainbow.Colours.Red;

, .

+15

- . , :

namespace Company.General.Project1
{
  [Flags]
  public enum Colours
  {
    Red,
    Blue,
    Orange
  }
}

using Company.General.Project1;

namespace Company.SpecialProject.Processing
{
  public class MixingPallette
  {
    int myValue = (int)Colours.Red;
  }
}

enum , :

using Company.General.Project1;

namespace Company.SpecialProject.Processing
{
  public class MixingPallette
  {
    int myValue = (int)Rainbow.Colours.Red;
  }
}
0

Source: https://habr.com/ru/post/1712445/


All Articles