开发者

sharing variables in a multi-project solution

I'm crea开发者_JAVA技巧ting 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.


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.


Always insure that Public methods, properties, fields, etc. names indicate a distinct context to avoid usage and maintenance confusion.

For example, a single solution having dozens of projects should not have identically named properties:

Project A: public int ThisValue{get;set;} -> ProjAThisValue Project B: public int ThisValue{get;set;} -> ProjBThisValue

Failing to do so creates referencing nightmares.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜