在多项目溶液共享变量 [英] sharing variables in a multi-project solution

查看:158
本文介绍了在多项目溶液共享变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是由3个项目的C#创建为Outlook 2010在VS2010的解决方案

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


  • 项目A - B和; C是依赖于这一个。它定义了某些变量/需要从B和可访问功能; ç

  • 项目B - 需要从读变量

  • 项目C - 需要从读变量

我没有得到远,但是,因为我似乎无法读取一个变量到b或C.我添加了一个作为参考这两个B和; C,但只有在一个空的分配在那些从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).

更​​多澄清:

这是一组3 Outlook加载项。

This is a set of 3 outlook add-ins.


  • 添加的A项目(其上别人依赖)调用的某些功能和提取信息到变量将由B和需要; ç

  • B&放; Ç包括一个完全集,分别根据这些信息必须为B和同样由A.收集的信息的功能; Ç在任何时候。

  • 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.

推荐答案

您可能需要过去的一些代码。但无论如何,确保项目A是一个类库。它应该是简单的:

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

项目A

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

项目b (有A作为参考)

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();
         }
     }
}

您就会有类似的东西在项目的 C

You'd have something similar in project C.

这篇关于在多项目溶液共享变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆