编译器警告(等级 1)CS3018

更新:2007 年 11 月

错误消息

“type”是不符合 CLS 的类型“type”的成员,因此不能将其标记为符合 CLS

如果将 CLSCompliant 属性设置为 true 的某一嵌套类声明为通过将 CLSCompliant 属性设置为 false 来声明的类的成员,将发生此警告。这是不允许的,因为如果嵌套类是不符合 CLS 的某一外部类的成员,它将无法符合 CLS。要解决此警告,请从嵌套类中移除 CLSCompliant 属性,或将其从 true 更改为 false。有关 CLS 遵从性的更多信息,请参见编写符合 CLS 的代码公共语言规范

示例

下面的示例生成 CS3018。

// CS3018.cs
// compile with: /target:library
using System;

[assembly: CLSCompliant(true)]
[CLSCompliant(false)]
public class Outer
{
   [CLSCompliant(true)]   // CS3018
   public class Nested {}

   // OK
   public class Nested2 {}

   [CLSCompliant(false)]
   public class Nested3 {}
}