包含非CLS兼容引用的程序集是否可以符合CLS?(Can an assembly that includes a non

编程入门 行业动态 更新时间:2024-10-08 00:27:18
包含非CLS兼容引用的程序集是否可以符合CLS?(Can an assembly that includes a non-CLS-compliant reference be CLS-compliant?)

我有一个现有的DLL不符合CLS,我从我自己的项目中引用。 当我将程序集标记为符合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.

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

最满意答案

是的,只要您的DLL不会向引用的程序集公开任何非CLS兼容的成员 - 也就是说,它不会在它自己的任何公共或受保护的成员或类型中提及它们。 (它仍然可以在私人和内部成员和类型中使用它们。)

如果您的DLL确实需要直接从不兼容的DLL中公开类型,您可以尝试在自己的包装中封装这些类型(例如,方法可能会返回MyWrapperAroundNaughtyType而不是NaughtyType ),或者您可以标记您的相关成员API CLSCompliant(false)只选择这些成员进行编译器检查。

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.)

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.

更多推荐

本文发布于:2023-04-29 08:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335580.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   CLS   includes   assembly

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!