简体   繁体   中英

How to verify F# code is CLS compliant

By marking the assembly for CLS compliance with [<assembly: CLSCompliant(true)>] I would expect the compiler to issue a warning if the assembly is not compliant. However, I can compile the following

type public Test() =
    member x.intA = 0;
    member x.INTA = 2;
    member x.MyMethod() = 8;
    member x.MYMETHOD() = 10;

without any warning what so ever. Target framework is 4.6 using F# 4.0. Am I missing something, or is it a bug in the compiler? Is there any other way to verify that an assembly generated from F# is compliant?

From this MSDN page you can see that the attribute is meant to mark the class as compliant and not to ensure compliance. Ensuring compliance is something that the compiler may or may not implement.

Checking the repositories for both Microsoft and FSharp you can see that the CLSCompliant attribute is never used to check for compliance. It is there just to mark the class as compliant, so this behaviour is normal.

Currentlyt I found no tools whatsoever to make this analysis in F#. I opened an issue to see if this feature is relevant enough to get implemented in the compiler. If it is, we all can help get it done. If it ain't, another option is writing an analyzer and releasing it as a VS plugin. Either way I'll keep this answer updated on any news regarding this subject.

You will need a tool to check as part of the build. This previous question has answers that discuss options, including FxCop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM