sharing variables in a multi-project solution

时光怂恿深爱的人放手 提交于 2019-12-02 08:06:06

问题


I'm creating a solution in VS2010 for Outlook 2010 using C# that is comprised of 3 projects.

  • Project A - B & C are dependent on this one. It defines certain variables/functions that need to be accessible from B & C
  • Project B - Needs to read variables from A.
  • Project C - Needs to read variables from A

I've not gotten far, yet, as I can't seem to read the variables from A into B or C. I've added A as a reference to both B & C, but assigning a local variable in one of those to the value from A results only in a null (which I know is not true).

More clarification:

This is a set of 3 outlook add-ins.

  • Add-in A of the project (on which the others are dependent) calls certain functions and pulls information into variables that will be needed by B & C
  • B & C comprise of a completely set of functions that are each depending on the information gleaned by A. This information needs to be the same for both B & C at all times.

回答1:


You might have to past some code. But anyway, ensure that project A is a class library. It should be as simple as:

Project A

namespace A
{
     public class AClass  // note, this is **public**
     {
         // ctor
         public AClass { }
         public void AMethod { }
     } 
}

Project B (has A as a reference)

using A;

namespace B
{
     public class BClass
     {
         // don't actually need "A" qualifier here as we're "using A" above, this is just for clarity
         private A.AClass aClass_ = new A.AClass();

         // ctor
         public BClass()
         {
             aClass_.AMethod();
         }
     }
}

You'd have something similar in project C.



来源:https://stackoverflow.com/questions/6821484/sharing-variables-in-a-multi-project-solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!