2011-08-28 72 views
0

mscorlib.xml(我注意到從摘要生成的XML文件),它包含:文檔化在C#代碼的異常

<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結尾?

+1

奇怪的問題,因爲你已經給自己答案:-) – Steven

回答

4

下面是一個例子:

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

換句話說,正是因爲代碼片段你已經表現出你的問題。

+0

我剛剛意識到:P。是否有任何提示使其更容易? – Will

+1

不,這就是它。 – Steven

+0

嗯,我想至少知道我不必輸入全名使得它更容易一些,所以非常感謝。是否有可以使用的元素和屬性列表? – Will

2

您可以在源代碼中的XML註釋中添加異常文檔和<exception>標記。例如:

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