我在一个名为Hasher的命名空间中有一个名为Hasher的类。所以完全限定的名称是:
Hasher.Hasher ...
我尝试在外部程序集(C#)中使用Hasher类。我已将命名空间导入到我的类中:
using Hasher;
但是当我尝试使用Hasher类时,编译器将无法找到它。
using Hasher;
namespace Test {
///<summary>
///This is a test class for HasherTest and is intended
///to contain all HasherTest Unit Tests
///</summary>
[TestClass()]
public class HasherTest {
///<summary>
///A test for GenerateFromRawData with null seed
///</summary>
[TestMethod()]
[ExpectedException( typeof( ArgumentNullException ) )]
public void GenerateFromRawDataTest_NullSeed() {
byte[] seed = null;
byte[] salt = null;
seed = null;
salt = null;
Hasher.GenerateFromRawData( seed, salt );
}
}
生成:
Error The type or namespace name 'GenerateFromRawData' does not exist in the namespace 'Hasher' (are you missing an assembly reference?) M:\j41833b_UR403088_ReportingDotNet\ReportingDotNet\src\AG385\_UnitTest\HasherTest.cs _UnitTest
我没有正确使用“使用”吗? (我的主要语言是VB.NET,所以我的C#有点生疏。粗略检查一下MSDN文档没有透露任何内容)
编辑:这很好。
namespace Test {
///<summary>
///This is a test class for HasherTest and is intended
///to contain all HasherTest Unit Tests
///</summary>
[TestClass()]
public class HasherTest {
///<summary>
///A test for GenerateFromRawData with null seed
///</summary>
[TestMethod()]
[ExpectedException( typeof( ArgumentNullException ) )]
public void GenerateFromRawDataTest_NullSeed() {
byte[] seed = null;
byte[] salt = null;
seed = null;
salt = null;
Hasher.Hasher.GenerateFromRawData( seed, salt );
}
}
答案 0 :(得分:3)
感谢@asawyer撰写以下文章:
有两个激光器。一,使用extern别名:
http://msdn.microsoft.com/en-us/library/ms173212(v=vs.100).aspx
二,重命名Hasher命名空间。 (当您控制源代码时,建议使用此选项,这是我选择的选项。)