在 C# 中禁用 CLS 合规性检查
我正在处理在其某些方法上具有以下属性的代码:
[CLSCompliantAttribute(false)]
当我按原样构建代码时,我看到正在执行合规性检查,当我将其注释掉时,似乎是这样的未执行合规性检查?
我预料到相反的行为......
I'm working on code that have the following attributes on some of its methods:
[CLSCompliantAttribute(false)]
How is it that when I build the code as is, I see that the compliance checking is being performed, and when I comment it out, it seems that the compliance checking is NOT being performed?
I've expected the opposite behavior...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加
[CLSCompliant(false)]
将您添加到的成员标记为不合规。如果您将该成员标记为不合规,则编译器不会在其不合规时发出警告。 (因为您已经说过它不兼容。)
但是,如果该成员被标记为兼容(显式或间接地从程序集级属性),但它实际上不兼容(例如,它需要一个
uint
),编译器会警告您(因为该属性现在位于该成员的周围)。Adding
[CLSCompliant(false)]
marks the member you add it to as non-compliant.If you mark the member as non-compliant, the compiler will not warn you if it isn't compliant. (Since you already said that it's not compliant.)
If, however, the member is marked as compliant (either explicitly or indirectly from an assembly-level attribute), but it is in fact not compliant (for example, it takes a
uint
), the compiler will warn you (since the attribute is now lying about the member).例如,您可以将其添加到 AssemblyInfo.cs,并将所有程序集分组:*。
喜欢 :
You can add it to AssemblyInfo.cs for example, and group all assembly:*.
Like :