Any reason not to mark a DLL as CLSCompliant?

佐手、 提交于 2019-12-10 02:36:48

问题


I am currently testing out Ndepend, and it gives me a warning that assemblies should be marked as CLSCompliant.

Our project is all C#, so it is not really needed.

What I am wondering is: are there any negative effects of marking a dll as clscompliant or should I just disable the warning?

Note I am not asking what CLSCompliant means that is covered here: What is the 'CLSCompliant' attribute in .NET?


回答1:


This is one of those subtle cases... CLS compliance is probably of most importance to library authors, who can't control who the caller is. In your case, you state "our project is all C#", in which case you are right: it isn't needed. It adds restrictions (for example, on unsigned types) which might (or might not) affect representing your data in the most obvious way.

So: if it adds no value to you whatsoever, then frankly: turn that rule off. If you can add it for free (no code changes except the attributes), then maybe OK - but everything is a balance - effort vs result. If there is no gain here, don't invest time.

If you are a library author (merchant or OSS), then you should follow it.




回答2:


There are several C# features that are not CLS compliant, for example unsigned types. Since several languages are case insensitive, there must be no types and members that differ only by case, e.g. MyObject and myObject, and several other features. Thus, if you don't plan to work with other .NET languages there is no reason to mark your code as CLSCompliant.




回答3:


The only negative effects would be compiler errors when your code is marked as CLSCompliant, but it is not.



来源:https://stackoverflow.com/questions/6982505/any-reason-not-to-mark-a-dll-as-clscompliant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!