CLSCompliant attribute default

  • Thread starter Thread starter Edward Diener
  • Start date Start date
E

Edward Diener

Is the default 'false' for the CLSCompliant attribute at the assembly
level ? Are there any tools to check for CLS compliance for the various
NET languages ?
 
Edward Diener said:
Is the default 'false' for the CLSCompliant attribute at the assembly
level ? Are there any tools to check for CLS compliance for the various
NET languages ?

The first part you could have found on your own, from msdn:
If no CLSCompliantAttribute is applied to a program element, then by
default:

a.. The assembly is not CLS-compliant.
b.. The type is CLS-compliant only if its enclosing type or assembly is
CLS-compliant.
c.. The member of a type is CLS-compliant only if the type is
CLS-compliant.
as for the second part, fxcop[1] will run across assemblies and give you
alot of information about the assembly, including naming and atleast some
cls compliance. Currently, any of MS's design guidelines that are revised
and posted(usually via Brad Abrams) contain suggestions for additional rules
to fxcop. It can also be extended to add your own rules.

1: http://www.gotdotnet.com/team/fxcop/
 
Daniel said:
The first part you could have found on your own, from msdn:
If no CLSCompliantAttribute is applied to a program element, then by
default:

a.. The assembly is not CLS-compliant.
b.. The type is CLS-compliant only if its enclosing type or
assembly is CLS-compliant.
c.. The member of a type is CLS-compliant only if the type is
CLS-compliant.

That is a bit confusing, but I have found the area in MSDN which explains
it. Obviously if no CLSCompliantAttribute is applied to a specific program
element, the assembly could still be CLS-compliant if the
CLSCompliantAttribute is applied to the assembly, so "a." is incorrect.
Furthermore if instead the above means "If no CLSCompliantAttribute is
applied to any program element", which would make "a." correct, then "b." or
"c." is irrelevant, but I don't think that is what it means. However, I do
gather from the above that the default for CLS compliance at the assembly
level is 'false', which is what I wanted to know from the original question.
as for the second part, fxcop[1] will run across assemblies and give
you alot of information about the assembly, including naming and
atleast some cls compliance. Currently, any of MS's design guidelines
that are revised and posted(usually via Brad Abrams) contain
suggestions for additional rules to fxcop. It can also be extended to
add your own rules.

1: http://www.gotdotnet.com/team/fxcop/

Thanks for the info on fxcop. I was not aware of this program and what it
does.
 
Edward Diener said:
That is a bit confusing, but I have found the area in MSDN which explains
it. Obviously if no CLSCompliantAttribute is applied to a specific program
element, the assembly could still be CLS-compliant if the
CLSCompliantAttribute is applied to the assembly, so "a." is incorrect.
Furthermore if instead the above means "If no CLSCompliantAttribute is
applied to any program element", which would make "a." correct, then "b." or
"c." is irrelevant, but I don't think that is what it means. However, I do
gather from the above that the default for CLS compliance at the assembly
level is 'false', which is what I wanted to know from the original question.

By my understanding, an assembly can be considered CLSCompliant if all of
its member types are CLSCompliant, however I'm not entirely sure, I
would(and do) simply play it safe and apply CLSCompliant liberally.
as for the second part, fxcop[1] will run across assemblies and give
you alot of information about the assembly, including naming and
atleast some cls compliance. Currently, any of MS's design guidelines
that are revised and posted(usually via Brad Abrams) contain
suggestions for additional rules to fxcop. It can also be extended to
add your own rules.

1: http://www.gotdotnet.com/team/fxcop/

Thanks for the info on fxcop. I was not aware of this program and what it
does.
 
Daniel said:
By my understanding, an assembly can be considered CLSCompliant if
all of its member types are CLSCompliant, however I'm not entirely
sure, I would(and do) simply play it safe and apply CLSCompliant
liberally.

One could always mark the assembly itself as CLSCompliant(true) I believe,
and then all enclosing types, meaning all the types in the assembly, become
CLSCompliant unless marked otherwise. I am not sure how one does this in the
assembly file but I am guessing it is just another attribute added to the
file.
 
Edward Diener said:
One could always mark the assembly itself as CLSCompliant(true) I believe,
and then all enclosing types, meaning all the types in the assembly, become
CLSCompliant unless marked otherwise. I am not sure how one does this in the
assembly file but I am guessing it is just another attribute added to the
file.
Yeah, generally in AssemblyInfo, for C# its [assembly: CLSCompliant(true)].
I think the rules apply when there is no CLSCompliant rule attached to the
assembly. I will look through the standards later on this issue as well.
 
Back
Top