在多项目解决方案中共享变量

发布于 2024-11-26 12:57:59 字数 560 浏览 4 评论 0原文

我正在使用 C# 在 VS2010 中为 Outlook 2010 创建一个解决方案,该解决方案由 3 个项目组成。

  • 项目A-B& C 依赖于此。它定义了需要从 B & 访问的某些变量/函数。 C
  • 项目 B - 需要从 A 读取变量。
  • 项目 C - 需要从 A 读取变量

我还没有走得太远,因为我似乎无法将变量从 A 读取到 B 或 C。我已经添加了A作为对B和B的引用; C,但将其中之一中的局部变量分配给 A 中的值只会导致 null(我知道这不是真的)。

更多说明:

这是一组 3 个 Outlook 插件。

  • 项目的加载项 A(其他项目依赖于此)调用某些函数并将信息提取到 B & 需要的变量 C
  • B& C 由一组完整的函数组成,每个函数都依赖于 A 收集的信息。对于 B 和 C 来说,该信息需要相同。任何时候都是C。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只涨不跌 2024-12-03 12:57:59

您可能必须传递一些代码。但无论如何,请确保项目 A 是一个类库。它应该像这样简单:

项目 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 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.

噩梦成真你也成魔 2024-12-03 12:57:59

始终确保公共方法、属性、字段等名称指示不同的上下文,以避免使用和维护混乱。

例如,具有数十个项目的单个解决方案不应具有相同名称的属性:

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

如果不这样做,就会造成引用噩梦。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文