【发布时间】:2016-04-04 06:49:27
【问题描述】:
我正在为我的程序编写单元测试,但遇到了两个不同项目中存在的我的类型错误。我试图通过在代码中添加一个项目名称来克服它:var status = CommunicationsServer.Status() 但它说那里不存在 Status() 类型。
请帮忙
这里是 CommunicationsServer.Status 类的前几行:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.mini.pw.edu.pl/ucc/")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.mini.pw.edu.pl/ucc/", IsNullable=false)]
public partial class Status {
private ulong idField;
private StatusThread[] threadsField;
/// <remarks/>
public ulong Id {
get {
return this.idField;
}
set {
this.idField = value;
}
}
//further code
}
【问题讨论】:
-
如果没有
CommunicationsServer和TaskManager中两种类型的额外上下文,就很难确定解决方案。为什么不在CommunicationsServer库中添加using语句?如果是静态类,请将using static放在命名空间和静态类型之前。如果您实际输入var status = CommunicationsServer.Status()它也可能不是静态类型,并且 VS 不知道您在引用什么。请提供有关冲突类型(命名空间、类声明等)的更多信息,您可能会得到更好的帮助。 -
上下文是什么意思? CommunicationServer 和 TaskManager 都是包含
public partial class Status类型的 Status 类的项目,我为该类创建了一个构造函数,我不应该需要我的类是静态的。 using语句如何实现? -
我用更多信息编辑了我的问题
-
在您编辑后,我还有一些问题。这个状态类是从一些 XML 到 C# 工具自动生成的吗?文件顶部的命名空间是什么?
-
是:
using CommunicationsServer;