Документирование исключения в коде C # - PullRequest
0 голосов
/ 28 августа 2011

Я заметил в mscorlib.xml (XML-файл, созданный из сводок), что он содержит:

<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" /> 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>

Из этого примера меня особенно интересует:

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

Как вы документируете исключения в коде, чтобы они попадали в XML?

Ответы [ 2 ]

4 голосов
/ 28 августа 2011

Вот пример:

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

Другими словами, точно так же, как фрагмент кода, который вы уже показали в своем вопросе.

2 голосов
/ 28 августа 2011

Вы можете добавить документацию по исключениям с тегом <exception> в комментариях XML в вашем исходном коде. Например:

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