开发者

Documenting an exception in C# code

开发者 https://www.devze.com 2023-03-31 01:22 出处:网络
I noticed in mscorlib.xml (the XML file that is generated from the summaries) that it contains: <member name=\"M:System.Console.ReadKey\">

I noticed in mscorlib.xml (the XML file that is generated from the summaries) that it contains:

<member name="M:System.Console.ReadKey">
  <summary>Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window.</summary>
  <returns>A <see cref="T:System.ConsoleKeyInfo" /> object that describes the <see cref="T:System.ConsoleKey" /&g开发者_如何学Got; constant and Unicode character, if any, that correspond to the pressed console key. The <see cref="T:System.ConsoleKeyInfo" /> object also describes, in a bitwise combination of <see cref="T:System.ConsoleModifiers" /> values, whether one or more SHIFT, ALT, or CTRL modifier keys was pressed simultaneously with the console key.</returns>
  <exception cref="T:System.InvalidOperationException">The <see cref="P:System.Console.In" /> property is redirected from some stream other than the console.</exception>
  <filterpriority>1</filterpriority>
</member>

From that example I am specifically interested in:

<exception cref="T:System.InvalidOperationException">The <see cref="P:System.Console.In" /> property is redirected from some stream other than the console.</exception>

How do you document exceptions in code so that they end up in the XML?


Here's an example:

/// <exception cref="ArgumentException">
/// Thrown when the <typeparamref name="TConcrete"/> is a type
/// that can not be created by the container.
/// </exception>

In other words, exactly as the code snippet you already showed in your question.


You can add the exception documentation with the <exception> tag in the XML comments in your source code. For example:

///<summary>Summary of method/property/etc</summary>
///<returns>Returns a value</returns>
///<exception>Throws an exception</exception>
0

精彩评论

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

关注公众号