2013-06-13 42 views
4

有一个关于C#编译器生成文档的问题。可空类型的文档生成

的源代码:

public class SomeClass { 
    /// <summary> 
    /// Do some work 
    /// </summary> 
    /// <returns cref="Nullable{Boolean}"> 
    /// Some stuff 
    /// </returns> 
    public bool? SomeMethod() { 
     return false; 
    } 
} 

编译器生成的方法的someMethod XML文档片段:

<member name="...." > 
.... 
    <returns cref="T:System.Nullable`1">SomeStuff</returns> 
</member> 

有没有什么办法,迫使它产生

<member name="...." > 
.... 
    <returns cref="T:System.Nullable{System.Boolean}">SomeStuff</returns> 
</member> 

代替?

+1

手动设置返回信息如下: 'cref =“T:System.Nullable {System.Boolean}”>' ? – dna

+0

哦,谢谢!那是行得通的!但是ReSharper生成Cannto解析符号。但我认为,ReSharper问题 – l0nley

+0

那么你可以'#pragma警告禁用',但它不是真正的眼睛糖果! – dna

回答

2

不幸的是没有。

无法更改.xml文件的生成方式。

相反,您将不得不更改处理这些文件以处理该语法的任何内容,或者更改XML文档。

这里的问题是Nullable{Boolean}Nullable{T}没有区别,因为括号之间的部分不被理解为类型,而是被理解为泛型类型参数。 T,Boolean,XYZ,这些都是一样的。

你将不得不改变读取这个工具(我不知道你将如何做到这一点),或不同写出您参考:

/// <returns> 
/// <see cref="Nullable{T}/> with <c>T</c> being <see cref="Boolean"/>. 
/// </returns> 
+0

这听起来很难过。 – l0nley

1

有关使用

Nullable<bool> 
如何
+0

如果我评论如下:”> - 其错误 – l0nley

+0

使用它在哪里? –

+0

'public Nullable SomeMethod(){}'insted'public bool? SomeMethod(){}' –

0

我使用以下语法:

/// <summary> 
/// Returns the field's value cast into <see cref="int"/>?. 
/// </summary> 
/// ... 
public int? GetNullableInt(string name, int? defaultValue = null) 

这意味着该类型的参考不是100%精确的,但第h强调文档的工具提示预览等同于签名预览的样子(彩色int,无色?)。