如何将一个或多个属性应用于项目中的所有类?

发布于 2024-09-19 13:20:12 字数 85 浏览 22 评论 0原文

如何将属性应用于特定项目中的所有类?! 仅将 CLSCompliant 属性应用于一个类就足够了,还是必须应用于所有类?

感谢您的回答...

How can I apply an attribute to all classes in a particular project?!
And is it enough to apply CLSCompliant attribute to just one class or do I have to apply to all classes?

Thanks for your answers...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我喜欢麦丽素 2024-09-26 13:20:12

这是属性的声明:

[SerializableAttribute]
[ComVisibleAttribute(true)]
[AttributeUsageAttribute(AttributeTargets.All, Inherited = true, AllowMultiple = false)]
public sealed class CLSCompliantAttribute : Attribute

注意 [AttributeUsage]。使用 AttributeTargets.All 表示该属性可以应用于任何内容。其中包括组件:

[assembly:CLSCompliant(true)]

This is the declaration for the attribute:

[SerializableAttribute]
[ComVisibleAttribute(true)]
[AttributeUsageAttribute(AttributeTargets.All, Inherited = true, AllowMultiple = false)]
public sealed class CLSCompliantAttribute : Attribute

Note the [AttributeUsage]. With AttributeTargets.All, it indicates that the attribute can be applied to anything. Which includes the assembly:

[assembly:CLSCompliant(true)]
怕倦 2024-09-26 13:20:12

项目是一个程序集,因此您可以使用程序集属性

A project is an assembly, so you could use an assembly attribute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文