Unity Tips – XML Comments

You can (and should) use XML comments to more effectively document your code, including Classes, Fields, Properties and Methods. XML comments will also populate the description for these elements when you hover over them in Visual Studio – this is particularly helpful for Classes that contain public members.

By using XML comments, you can then simply hover over the public member being used in another class and Visual Studio will give you the summary of what that member does.

An example of XML comments in Visual Studio

You can quickly add the template of an XML comment by typing ‘///’ above the member you want to comment. Visual Studio will automatically populate the <summary> structure for you, and give you the appropriate return and argument tags included in the new comment.

You can also use these XML comments to generate HTML documentation using tools such as Doxygen, and preview these types of documentation within Visual Studio with extensions like DocPreview.

DocPreview’s generated XML documentation for this method example.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s