帮助我使用CLSCompliant属性: [英] Help me out to use CLSCompliant Attribute:

查看:133
本文介绍了帮助我使用CLSCompliant属性:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:



使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Text;

[assembly:CLSCompliant(true)]

命名空间AttributeCLSComplaint

{

class Abc

{

UInt32 y;

[CLSCompliant(true)]

public UInt32 meth1()

{

UInt32 x = 10; ut

返回x;

}

}

class program

{

static void Main(string [] args)

{

Abc a = new Abc();

UInt32 x = a.meth1();

控制台。 WriteLine(x);

}

}



}



我的主题是在这里使用CLSCompliant属性;根据需要,我写了所有必需的属性但是收到警告:不会对AttributeCLSComplaint.Abc.meth1()执行CLS合规性检查,因为从该程序集外部看不到通过在下面显示警告符号:CLSComplaint( true)高于meth1()..

This is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
[assembly:CLSCompliant(true)]
namespace AttributeCLSComplaint
{
class Abc
{
UInt32 y;
[CLSCompliant(true)]
public UInt32 meth1()
{
UInt32 x = 10;ut
return x;
}
}
class Program
{
static void Main(string[] args)
{
Abc a = new Abc();
UInt32 x=a.meth1();
Console.WriteLine(x);
}
}

}

My theme is to use CLSCompliant Attribute over here; As needed, i wrote all the required attributes but am getting a warning: "CLS compliance checking will not be performed on AttributeCLSComplaint.Abc.meth1() because it is not visible from outside this assembly" by showing a warning symbol below: CLSComplaint(true) which is above meth1()..

推荐答案

基本上,它告诉你该方法的使用 meth1() 毫无意义。使用你的程序集对程序集是不可见的,因为它的声明类是不可见的。



你应该考虑这个属性的应用程序。你确定你真的需要吗?基本上,您告诉可能使用您的程序集但使用其他语言编写的程序集,您的程序集符合CLS。与您的装配相比,非CLS兼容功能可能会限制该外语;它可能会产生一些问题。但你真的想为这种情况作出规定吗?无论如何,如果您想要开发一个CLS兼容的API及其不符合CLS的扩展,您只需要标记一些具有此属性的单独类型或成员;然后你会用这个属性标记一个CLS编纂子集。即使你想要它,它会实用吗?您可以使用一个单独的程序集来引用具有不符合CLS的公共代码的程序集(并明确地将所有这些程序集标记为CLS兼容)。



另一个用例可能是在.NET之外的替代CLR实现下执行代码。某些运行时系统可能设计为仅加载符合CLS的程序集。但是,我不知道这样的实现;它们都超出了CLS的标准。



请参阅:

http://msdn.microsoft.com/en-us/library/bhc3fa7f%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/ en-us / library / system.clscompliantattribute.aspx [ ^ ],

http:// forums。 asp.net/t/1315820.aspx/1 [ ^ ]。



-SA
Basically, it tells you that the use of this attribute for the method meth1() makes no sense. It is invisible to the assembly using your assembly because its declaring class is invisible.

You should think about applications of this attribute. Are you sure you really need it? Basically, you tell the assembly that may use your assembly but written in a different language, that your assembly is CLS-compliant. That foreign language may be limited in the non-CLS-compliant features compared to your assembly; and it may create some problems. But do you really want to make provisions for such situations? Anyway, you only need to mark some separate types or members with this attributes if you want to develop a CLS-compilant set of API plus its extension which is not CLS-compliant; then you would mark a CLS-compilant subset with this attribute. Even if you want it, will it be practical? You could have a separate assembly referencing an assembly with common code which is not CLS-compliant (and explicitly mark all those assemblies as CLS-complient or not).

Another use case could be executing your code under alternative CLR implementation, other than .NET. Some runtime systems might be designed to load only the CLS-compliant assemblies. However, I don''t know such implementations; they all go beyond the standard for CLS.

Please see:
http://msdn.microsoft.com/en-us/library/bhc3fa7f%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.clscompliantattribute.aspx[^],
http://forums.asp.net/t/1315820.aspx/1[^].

—SA


这篇关于帮助我使用CLSCompliant属性:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆