Where do Visual Studio Intellisense comments come

2019-02-08 08:05发布

问题:

Visual Studio projects have an option to create XML Documentation Files. I understand that XML Documentation Files can be useful if you'd like to run a program like Sandcastle or NDoc or whatever to create MSDN-Style API docs. Fine. I don't care about that.

According to this link: http://msdn.microsoft.com/en-us/library/s0we08bk.aspx

When you add the /doc switch to the Visual Basic, C#, or C++ compiler command line, an .xml file is generated that serves as the basis for IntelliSense documentation.

So that makes me think that Intellisense comments can appear from these generated XML files.

But I created a little Test app where I call a method in a totally different project and the XML comment appears in my Intellisense — And I haven't even saved the MediaHelper class! So in this case it's obvious there is no .xml file that Intellisense is using.

In light of all this, where does Intellisense get it's junk from? Thanks!

回答1:

When the source code is within the existing solution (or even better, the same project), Visual Studio doesn't need to find an XML file - it knows where the documentation comments are, so it will use them. (Just like Intellisense knows what members you've declared in the other file, even if you haven't actually rebuilt yet.)

You need to create an XML file if you want to add a reference to a DLL rather than a project reference within the same solution. So for example, I supply NodaTime.xml with the Noda Time package, so that even though you don't have the source code, you can still see the comments in Intellisense.



回答2:

Intellisense gets it from its XML comments.

For example, let's say I have a class:

///<summary>
/// This is an example class
///</summary>
static class Foo
{
    //members
}

In fact, you can go even deeper than that. For example, a method:

///<summary>
///Returns the object to string, uppercased.
///</summary>
///<param name="o">The object to be transformed.</param>
///<returns>The string.</returns>
public string someMethod(object o)
{
   return o.ToString().ToUpper();
}