I am working with a WPF application in C#. I have a number of constants defined in a static class as the following:
Project1:
namespace MyCompany
{
public static class Constants
{
public static int MY_CONSTANT = 123456;
}
}
Then all I need to do to access my constant anywhere inside Project 1 is:
int x = Constants.MY_CONSTANT;
Now I add another project to the same solution, and use 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 a way to access my static Constants class from the second assembly. I also can't add a reference to the first assembly, because it leads to circular dependency (the second project assembly is a WPF control used by the first project assembly).
Is what I'm trying to do even possible? Currently my workaround is passing all the required constants in constructor, but I'd rather just access them directly.
You can move all of the static constants from project 1 to project 2, therefore, all of the constants are visible to both project 1 and project 2; I recommended that introduce another project (maybe common) which could help to manage all of the stuffs that shared by all of the other projects. it's a common infrastructure project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With