我正在编写一些方法具有以下属性的代码:
[CLSCompliantAttribute(false)] 为什么当我按原样构建代码时,我看到正在执行遵从性检查,而当我注释掉它时,似乎没有执行遵从性检查?
我已经预料到了相反的行为。
发布于 2010-11-02 01:29:36
添加[CLSCompliant(false)]会将添加到其中的成员标记为不符合。
如果您将成员标记为不符合,编译器将不会警告您它不符合。(因为您已经说过它不符合。)
但是,如果该成员被标记为符合(显式或间接来自程序集级属性),但它实际上是不符合的(例如,它接受uint),编译器将警告您(因为该属性现在位于关于该成员的位置)。
发布于 2017-03-28 20:51:18
例如,您可以将其添加到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")]https://stackoverflow.com/questions/4071375
复制相似问题