cls-compliant

When is it acceptable to break CLS compliance?

旧巷老猫 提交于 2019-12-10 11:30:12
问题 I was wondering which edge cases exist that could make Common Language Specification compliance acceptable. Even when not intending to be accessed from other languages, I think that the tenets asserted by the CLSCompliantAttribute are good best practices. Do you have encountered / know of cases where YAGNI outweighs the best practices? 回答1: "[sic] What use is there for being CLS compliant?" Medium trust, ClickOnce, running from a shared network drive, guest profiles in a domain setting, etc.

CLS compliant attributes and array parameters

跟風遠走 提交于 2019-12-10 04:24:36
问题 I have created an attribute that accepts a (params) array in its constructor. internal class MyTestAttribute : Attribute { public MyTestAttribute (params Options[] options) { .... } } Option here is an enum (with lots of values), so a sample call site will be [MyTest(Option.One, Option.Three)] internal void SomeMethod(int param1, long param2) { .... } Everything is peachy so far, and the setup works, but I'm receiving an " Arrays as attribute arguments is not CLS-compliant " warning on each

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

Can an assembly that includes a non-CLS-compliant reference be CLS-compliant?

爷,独闯天下 提交于 2019-12-08 17:13:59
问题 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? 回答1: 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

Why is overloaded method differing in ref only CLS compliant

怎甘沉沦 提交于 2019-12-07 00:02:30
问题 Common Language Specification is quite strict on method overloads. Methods are allowed to be overloaded only based on the number and types of their parameters, and in the case of generic methods, the number of their generic parameters. Why is this code CLS compliant (no CS3006 warning) according to csc? using System; [assembly: CLSCompliant (true)] public class Test { public static void Expect<T>(T arg) { } public static void Expect<T>(ref T arg) { } public static void Main () { } } 回答1: This

When is it acceptable to break CLS compliance?

和自甴很熟 提交于 2019-12-06 13:23:06
I was wondering which edge cases exist that could make Common Language Specification compliance acceptable. Even when not intending to be accessed from other languages, I think that the tenets asserted by the CLSCompliantAttribute are good best practices. Do you have encountered / know of cases where YAGNI outweighs the best practices? Jason Short "[sic] What use is there for being CLS compliant?" Medium trust , ClickOnce , running from a shared network drive, guest profiles in a domain setting, etc. There are lots of security situations where your code cannot run if you break the CLS

Any reason not to mark a DLL as CLSCompliant?

蹲街弑〆低调 提交于 2019-12-05 02:17:00
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? 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

Is the new feature of C# 4.0 - “Optional Parameters” CLS-Compliant?

时光怂恿深爱的人放手 提交于 2019-12-04 08:51:40
问题 This new feature is really convenient. Lately I read the document of the "Microsoft All-In-One Code Framework", and it mentions that "Optional Parameters" is not CLS-Compliant. So I tested it by using "Optional Parameters" in a public API, and turned on FxCop, then I compiled and FxCop did not complain about anything. At the mean while, FxCop did report a warning when I add an API that has uint as its return type. So now I am confused, is "Optional Parameters" CLS-Compliant or not? And what's

Is the new feature of C# 4.0 - “Optional Parameters” CLS-Compliant?

限于喜欢 提交于 2019-12-03 01:08:16
This new feature is really convenient. Lately I read the document of the "Microsoft All-In-One Code Framework", and it mentions that "Optional Parameters" is not CLS-Compliant. So I tested it by using "Optional Parameters" in a public API, and turned on FxCop, then I compiled and FxCop did not complain about anything. At the mean while, FxCop did report a warning when I add an API that has uint as its return type. So now I am confused, is "Optional Parameters" CLS-Compliant or not? And what's the best way to find out whether a new language feature is CLS-Compliant or not? Optional arguments

Why is my class not CLS-compliant?

让人想犯罪 __ 提交于 2019-12-01 16:47:29
This really baffles me. I've tried removing the readonly, changing names.. What am I doing wrong here? public abstract class CatalogBase<T> where T : class { protected readonly String DataPath; protected readonly XmlSerializer Serializer; private readonly XmlSerializerNamespaces _namespaces; protected CatalogBase(String dataPath) { DataPath = dataPath; Serializer = new XmlSerializer(typeof (T)); _namespaces = new XmlSerializerNamespaces(); _namespaces.Add(String.Empty, String.Empty); } public virtual void Write(T obj) { var streamWriter = new StreamWriter(DataPath); Serializer.Serialize