7

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

[CLSCompliantAttribute(false)] 

当我按原样构建代码时,我如何看到正在执行合规性检查,而当我将其注释掉时,似乎没有执行合规性检查?

我已经预料到相反的行为......

4

2 回答 2

9

添加[CLSCompliant(false)]将您添加到的成员标记为不合规。

如果您将该成员标记为不合规,则编译器不会在它不合规时向您发出警告。(因为您已经说过它不合规。)

但是,如果该成员被标记为兼容(显式或间接来自程序集级属性),但它实际上不兼容(例如,它需要一个uint),编译器会警告您(因为该属性现在是对会员撒谎)。

于 2010-11-01T17:29:36.227 回答
3

例如,您可以将其添加到 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")]
于 2017-03-28T12:51:18.220 回答