在 C# 中禁用 CLS 合规性检查

发布于 2024-09-30 07:38:50 字数 168 浏览 0 评论 0原文

我正在处理在其某些方法上具有以下属性的代码:

[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 技术交流群。

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

发布评论

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

评论(2

我乃一代侩神 2024-10-07 07:38:50

添加 [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).

风和你 2024-10-07 07:38:50

例如,您可以将其添加到 AssemblyInfo.cs,并将所有程序集分组:*。
喜欢 :

using System;
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: CLSCompliant(false)]


// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is     exposed to COM
[assembly: Guid("d29c53b6-88e4-4b33-bb86-f39b4c733542")]

// Version information for an assembly consists of the following four     values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build     Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

You can add it to AssemblyInfo.cs for example, and group all assembly:*.
Like :

using System;
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: CLSCompliant(false)]


// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is     exposed to COM
[assembly: Guid("d29c53b6-88e4-4b33-bb86-f39b4c733542")]

// Version information for an assembly consists of the following four     values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build     Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文