简体   繁体   English

程序集访问

[英]Assembly access

If you have a assembly identity/namespace of Library.Testing . 如果您具有Library.Testing的程序集标识/名称空间。 Then you created another assembly with identity/namespace of Library.Testing.One Library.Testing.One project references Library.Testing . 然后,你创造了另一个组件,身份/命名空间Library.Testing.One Library.Testing.One项目引用Library.Testing

Why is it you have to use using Library.Testing; 为什么必须using Library.Testing;来使用using Library.Testing; in your classes in Library.Testing.One to access anything in Library.Testing ? 在你的类Library.Testing.One访问任何东西Library.Testing

Example1: 例1:

using System;

namespace Library.Testing.One
{
    // 'Library.Testing' is a reference in this assembly
    public class foo : Library.Testing.BooBase
   {
   }
}

This does not work I get two exception 这不起作用我得到两个异常

Warning 1 Load of property 'RootNamespace' failed. 警告1加载属性'RootNamespace'失败。 The string for the root namespace must be a valid identifier. 根名称空间的字符串必须是有效的标识符。 Error 2 The type or namespace name 'BooBase' does not exist in the namespace 'Library.Testing.One.Library.Testing' (are you missing an assembly reference?) 错误2类型或名称空间名称'BooBase'在名称空间'Library.Testing.One.Library.Testing'中不存在(您是否缺少程序集引用?)

Example2: 例2:

using System;
using Library.Testing;

namespace Library.Testing.One
{
    // 'Library.Testing' is a reference in this assembly
    public class foo : Library.Testing.BooBase
   {
   }
}

This works! 这可行!

Adding a "using" for Library.Testing.One does not automatically bring everything in Library and Library.Testing into scope. Library.Testing.One添加“使用”不会自动将LibraryLibrary.Testing所有内容都纳入范围。 The fact that the namespaces appear to be hierarchical is probably what's leading to your confusion. 名称空间看起来是分层的,这可能导致您感到困惑。

Think of, for example, adding using System.Data.SqlClient to a file. 例如,考虑using System.Data.SqlClient向文件中添加。 That doesn't automatically bring everything in System and System.Data into scope. 这不会自动将SystemSystem.Data所有内容都纳入范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM