我正在研究在某些方法上具有以下属性的代码:
[CLSCompliantAttribute(false)]
当我按原样构建代码时,我看到正在执行合规性检查,当我将其注释掉时,似乎没有执行合规性检查?
我期待相反的行为......
答案 0 :(得分:9)
添加[CLSCompliant(false)]
会将您添加的成员标记为不合规。
如果您将该成员标记为不合规,则编译器不会警告您是否不合规。 (因为你已经说它不合规了。)
但是,如果成员被标记为兼容(显式或间接来自程序集级属性),但实际上它不符合(例如,它需要uint
),编译器将警告你(因为该属性现在是关于成员的。)
答案 1 :(得分:2)
例如,您可以将它添加到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")]