How to access a static class in the same namespace but in a different assembly?

I am working with a WPF application in C #. I have a number of constants defined in a static class as follows:

Project1:

namespace MyCompany
{
   public static class Constants
   {
      public static int MY_CONSTANT = 123456;
   }
}

Then, all I need to do to access my constant anywhere in project 1 is:

int x = Constants.MY_CONSTANT;

Now I am adding another project to the same solution and using the same root namespace:

Project 2

namespace MyCompany.MyControl
{
   class VideoControl
   {
      int x;
      x = Constants.MY_CONSTANT; //<-- doesn't work
      x = MyCompany.Constants.MY_CONSTANT; //<-- doesn't work either
   }
}

I just can't figure out how to access my static Constants class from the second assembly. I also can’t add a link to the first assembly because it leads to a cyclical dependency (the second build of the project is the WPF control used by the first build of the project).

, ? , .

+5
3

1 2, 1, 2; (, ), , . .

+2

Another answer is close, but actually the opposite: project 2 requires a link to project 1. Then the code must be compiled.

EDIT:

Sorry, I see that you have already considered this. Yes, someone commented to avoid the circular addiction problem by introducing a third build.

0
source

All Articles