包含非CLS兼容引用的程序集是否符合CLS? [英] Can an assembly that includes a non-CLS-compliant reference be CLS-compliant?

查看:195
本文介绍了包含非CLS兼容引用的程序集是否符合CLS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的DLL不符合CLS,我从我自己的项目引用。当我将我的程序集标记为CLS兼容时,我得到编译器警告,引用程序集中的名称不符合CLS。

I have an existing DLL that is not CLS-compliant that I reference from my own project. When I mark my assembly as CLS-compliant, I get compiler warnings that names in the referenced assembly are not CLS-compliant.

有一种方法可以保留我的程序集CLS兼容,并标记引用的不是?

Is there a way I can keep my assembly CLS-compliant and mark the referenced one as not?

推荐答案

是的,你的DLL可以符合CLS,不会从引用的程序集中暴露任何非CLS兼容成员 - 也就是说,它不会在任何自己的公共或受保护成员或类型中提及它们。 (它仍然可以在私有和内部成员和类型中使用它们。)

Yes, your DLL can be CLS-compliant as long as it doesn't expose any non-CLS-compliant members from the referenced assembly -- that is, it doesn't mention them in any of its own public or protected members or types. (It can still use them in private and internal members and types.)

如果你的DLL需要从不兼容的DLL直接暴露类型,你可以试试将这些类型封装在你自己的包装器中(例如,一个方法可能返回 MyWrapperAroundNaughtyType 而不是 NaughtyType ),标记您的API CLSCompliant(false)的相关成员,以便仅选择这些成员进行编译器检查。

If your DLL does need to expose types directly from the non-compliant DLL, you can either try encapsulating those types in your own wrappers (e.g. a method might return a MyWrapperAroundNaughtyType instead of a NaughtyType), or you can mark the relevant members of your API CLSCompliant(false) to opt just those members out of compiler checking.

这篇关于包含非CLS兼容引用的程序集是否符合CLS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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