c# - "internal class"不是在一个库中编译,而是在一个新的类库中工作

标签 c#

我有一个内部属性,它在定义它的程序集中不可见。

属性

namespace Stuff {

  [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
    internal sealed class LogActionsAttribute : Attribute {

        internal LogActionsAttribute() { }
    }
}

此类在同一程序集中定义并产生编译错误。

namespace OtherStuff {

  [Stuff.LogActionsAttribute]
    class MyClass {

        void D() {


        }
    }

}

错误 1 ​​命名空间“Stuff”中不存在类型或命名空间名称“LogActionsAttributeAttribute”(是否缺少程序集引用?)

有什么想法吗?

最佳答案

如果该类型在项目内部,则可能是命名空间冲突;尝试:

[global::Stuff.LogActions]
class MyClass { ... }

这避免了与其他命名空间中的 Stuff 发生冲突。

关于c# - "internal class"不是在一个库中编译,而是在一个新的类库中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5141644/

相关文章:

c# - 在滚动条上的 WPF TreeView 中拖放

c# - 在 C# 中使用 "as"是一种安全的转换方式吗?

c# - 如何不从 linq 查询返回 {ModuleName = Admin}?

c# - 如何将计算机音频传递给程序以进行可视化?

c# - BodyFrameReader.AcquireLatestFrame 总是返回 null

c# - 是否可以在当前 appdomain/trace 输出中运行 roslyn 输出到 ASP 页面?

c# - Windows服务(错误1053)事件日志触发器

c# - 如何使 Style 通用以便我可以在我的整个应用程序中使用它?

c# - 从 WebAPI 返回自定义 HTTP 状态代码?

c# - 使用 LINQ 将元素读入字典对象