.net - Is the new feature of C# 4.0 - "Optional Parameters" CLS-Compliant? -


This new feature is really convenient.

Recently I have "Microsoft serv-in" - a code framework ", and it has been mentioned that" optional parameter "is not CLS-compliant.

In the public API, using the "Alternate Parameters" test, and started FxCop, then I compiled and Fxcop did not complain anything.In the meantime, when I added an alert when FXCOP had reported a warning, Use The type of C is UIT.

So now I am confused, "alternative parameter" is CLS-compliant or not?

And what is the best way to find out that someone Whether the new language feature is CLS-compliant?

Optional logic "sort of" CLS-contract is optional The laws with the arguments are legal and the CLSCompliant attribute of these methods, but It can not be taken, it does not need to take the original parameter values ​​or the account's account. Optional attribute (in that case, those methods will behave in the same manner as the standard method, for which all the logic is clearly on the call site To be called.)

Methods that use the default parameters Common Language Specification (CLS); However, the CLS compiler allows these standards to ignore the values ​​specified. The code that is written for the compiler, which ignores the default parameter values, must explicitly provide logic for each default parameter. To maintain the behavior that you want in programming languages, those methods that use the default parameters should be replaced with a method overload that provides the default criteria.

(taken for the document.)

Comments