好的,我很难过:为什么一个类不符合CLS,当它的唯一构造函数有一个urls.py
参数而该类继承自System.TimeSpan
?
这是一个min-repro,另外证明System.Attribute
和System.Attribute
符合 CLS:
System.TimeSpan
编译运行:
using System;
[assembly:CLSCompliant(true)]
namespace Test
{
public class CLSCompliantClass1
{
public TimeSpan Foo; // CLS-compliant
public CLSCompliantClass1(TimeSpan bar) { } // CLS-compliant
}
public class CLSCompliantClass2 : Attribute
{
public TimeSpan Foo; // CLS-compliant
public CLSCompliantClass2(double foo) { } // CLS-compliant
}
public class NonCLSCompliantClass : Attribute
{
// 'Test.NonCLSCompliantClass' has no accessible constructors which use only CLS-compliant types
public NonCLSCompliantClass(TimeSpan bar) { } // not CLS-compliant??
}
}
(任何>csc /t:library cls.cs /warnaserror /nologo
cls.cs(19,15): error CS3015: Warning as Error: 'Test.NonCLSCompliantClass' has no accessible constructors which use only CLS-compliant types
的重印)