在多项目解决方案中共享变量
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能必须传递一些代码。但无论如何,请确保项目 A 是一个类库。它应该像这样简单:
项目 A
项目 B(以 A 作为参考)
您在项目 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
Project B (has A as a reference)
You'd have something similar in project C.
始终确保公共方法、属性、字段等名称指示不同的上下文,以避免使用和维护混乱。
例如,具有数十个项目的单个解决方案不应具有相同名称的属性:
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.