为什么我的标识符被标记为不符合 CLS?

发布于 2024-12-06 10:19:03 字数 358 浏览 0 评论 0原文

我有一个类,其中包含三个字段:

protected bool _isRunning = false;

protected readonly ParameterCollection _parameters = null;

protected readonly ParameterCollection _defaultParameters = null;

它所在的程序集被标记为符合 CLS(这是必需的),而 Visual Studio 2010 表示这三个字段的标识符不符合 CLS。他们有什么问题吗?

PS:ParameterCollection是一个类,派生自KeyedCollection,如果它是重要信息。

I have a some class, which contains three fields:

protected bool _isRunning = false;

protected readonly ParameterCollection _parameters = null;

protected readonly ParameterCollection _defaultParameters = null;

The assembly it is in is marked as CLS-compliant (it is needed), and Visual Studio 2010 says that those three fields' identifiers are not CLS-compliant. What is wrong with them?

P.S.: ParameterCollection is a class, derived from KeyedCollection, if it is important information.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

脱离于你 2024-12-13 10:19:03

以下是 Microsoft 的答案,来自 Name不符合 CLS

纠正此错误

如果您可以控制源代码,请更改成员名称,使其不以下划线开头。

如果您要求成员名称保持不变,请从其定义中删除 CLSCompliantAttribute 或将其标记为 .您仍然可以将程序集标记为

Here is the answer from Microsoft, from Name <membername> is not CLS-compliant:

To correct this error

If you have control over the source code, change the member name so that it does not begin with an underscore.

If you require that the member name remain unchanged, remove the CLSCompliantAttribute from its definition or mark it as . You can still mark the assembly as <CLSCompliant(True)>.

窝囊感情。 2024-12-13 10:19:03

他们怎么了?

它们以下划线开头。

有关更多详细信息,请参阅此处

根据 MSDN

符合 CLS 的语言编译器必须遵循附件 7 的规则
管理该集的 Unicode 标准 3.0 技术报告 15
可以开始并包含在标识符中的字符。这
标准可在
http://www.unicode.org/unicode/repor.. .5/tr15-18.html。两人份
标识符被认为是不同的,它们的差异必须大于
只是他们的情况。

来自 Unicode 标准 3.0 技术报告 15,附件 7:

即标识符的第一个字符可以是大写字母,
小写字母、标题大写字母、修饰符字母、其他字母或字母
数字。标识符的后续字符可以是其中任何一个,加上
非间距标记、间距组合标记、小数、连接器
标点符号和格式代码(例如右左标记)。通常情况下
在存储或比较之前应过滤掉格式化代码
标识符。

what's wrong with them?

They start with an underscore.

For more details, see here:

According to MSDN:

CLS-compliant language compilers must follow the rules of Annex 7 of
Technical Report 15 of the Unicode Standard 3.0, which governs the set
of characters that can start and be included in identifiers. This
standard is available at
http://www.unicode.org/unicode/repor...5/tr15-18.html. For two
identifiers to be considered distinct, they must differ by more than
just their case.

from Unicode Standard 3.0 Technical Report 15, Annex 7:

That is, the first character of an identifier can be an uppercase letter,
lowercase letter, titlecase letter, modifier letter, other letter, or letter
number. The subsequent characters of an identifier can be any of those, plus
non-spacing marks, spacing combining marks, decimal numbers, connector
punctuations, and formatting codes (such as right-left-mark). Normally the
formatting codes should be filtered out before storing or comparing
identifiers.

不必在意 2024-12-13 10:19:03

要符合 CLS,标识符必须遵循 Unicode 标准技术报告 15 的附件 7 (MSDN)。这包括第一个字符为字母的要求 ()。

To be CLS compliant, identifiers must follow the guidelines in Annex 7 of Technical Report 15 of the Unicode Standard (MSDN). This includes the requirement that the first character be a letter (source).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文