我有一个现有的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.
更多推荐
发布评论