简体   繁体   中英

C# Visual Studio Intellisense without XML tags

Is there a way to get Visual Studio 2019 (Enterprise) to recognise non-XML docstrings for Intellisense so that when you mouse over it, it will display the summary, parameters, etc.? Specifically, in the same vein that docstring is formatted in the C# SDKs.

For example, for Thread.Sleep(millisecondsTimeout) it has the following docstring:

    //
    // Summary:
    //     Suspends the current thread for the specified number of milliseconds.
    //
    // Parameters:
    //   millisecondsTimeout:
    //     The number of milliseconds for which the thread is suspended. If the value of
    //     the millisecondsTimeout argument is zero, the thread relinquishes the remainder
    //     of its time slice to any thread of equal priority that is ready to run. If there
    //     are no other threads of equal priority that are ready to run, execution of the
    //     current thread is not suspended.
    //
    // Exceptions:
    //   T:System.ArgumentOutOfRangeException:
    //     The time-out value is negative and is not equal to System.Threading.Timeout.Infinite.

This is what appears: Intellisense tooltip

I find the idea of the XML tags ( <param>millisecondsTimeout</param> ) harms readability whilst looking at code and was wondering if there was a way to make it more similar to Java's JavaDoc, which isn't as difficult to read through.

This cannot be done directly in VS, as already mentioned, you need an extension for such functionality. But I'm not aware of any.

On the other hand, even the .NET framework itself uses XML comments. What you mentioned for Thread.Sleep(millisecondsTimeout) was just what VS presented to you from metadata when you press F12 on the method call. In fact, this method has the following XML comment:

<summary>
Suspends the current thread for the specified number of milliseconds.
</summary>
<param name="millisecondsTimeout">
The number of milliseconds for which the thread is suspended. If the value of the <paramref name="millisecondsTimeout" /> argument is zero, 
the thread relinquishes the remainder of its time slice to any thread of equal priority that is ready to run. 
If there are no other threads of equal priority that are ready to run, execution of the current thread is not suspended.
</param>
<exception cref="T:System.ArgumentOutOfRangeException">
The time-out value is negative and is not equal to <see cref="F:System.Threading.Timeout.Infinite" />.
</exception>

Visual Studio and Intellisense take it from the XML file that you can find in a location like C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETFramework\\v4.X\\mscorlib.xml.

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