开发者

Is it possible to mark a module function as "hidden" from Intellisense discovery?

开发者 https://www.devze.com 2023-03-16 02:37 出处:网络
As a follow up to this question, I am wondering whether it is possible to mark an F# function within a module (presumably via an attribute) as \"hidden\" from Intellisense. To recap, I have some funct

As a follow up to this question, I am wondering whether it is possible to mark an F# function within a module (presumably via an attribute) as "hidden" from Intellisense. To recap, I have some functions which are marked inline but are implemented in terms of other functions I don't really want to expose. So while the implementation functions must be kept public (since they are being inlined), I r开发者_StackOverflow中文版emember that in the past I've come across C# methods which were hidden from Visual Studio Intellisense but compiled just fine if you knew what they were, but I don't remember the exact method(s) and am unsure if that was some sort of ad-hoc Visual Studio thing or a usable feature like DebuggerBrowsable(DebuggerBrowsableState.Never) awareness.

Update: I tried applying the EditorBrowsable(EditorBrowsableState.Never) but it doesn't appear to work in Visual F# projects.


I tried to do that recently and I'm pretty sure that F# ignores the EditorBrowsable attribute.

The only way to make declaration disappear from the IntelliSense is to use the ObsoleteAttribute, but that also means you'll get a warning when you actually use the function. This is a bit unfortunate, but it may be okay if you use the function only from some implementation file where you can disable the warning:

Declaration in one file:

module Internal = 
  [<System.ObsoleteAttribute>]
  let foo = 10

Implementation file that disables warnings and uses foo:

// Disable 'obsolete' warning
#nowarn "44"

// 'Internal' is empty (and is not shown in the completion list)
Internal.foo

The attribute can be applied to modules, functions and types, so it is quite flexible.


You can use [EditorBrowsable(EditorBrowsableState.Never)], but this will only work for clients of your assembly that are not in the same solution (i.e. importing your class library as an assembly and not as a Project.) Projects in the same solution will still show the methods in Intellisense.

0

精彩评论

暂无评论...
验证码 换一张
取 消