你可以在我的构造函数中继承类的文档字符串。

huangapple go评论70阅读模式
英文:

How can I inherit the docstring of the class in my constructor

问题

/// <summary>
/// 在这种情况下,用户是新加入群组的,但可能以前就存在。
/// </summary>
class NewUserData {
    public User user;
    // 更多数据字段在这里...

    public NewUserData(){ 
        // 在这里创建测试数据...
    }
}
var data = new NewUserData();

在IDE(Visual Studio)中悬停在 NewUserData 上不会显示文档字符串。是否有办法让它在不将文档字符串移到构造函数下面的情况下显示?


<details>
<summary>英文:</summary>

I have a class to generate test data that I have documented with a docstring.

```csharp
/// &lt;summary&gt;
/// In this scenario the user is new to the group, but may have existed from before.
/// &lt;/summary&gt;
class NewUserData {
    public User user;
    // More data fields here ...

    public NewUserData(){ 
        // Creating test data here ...
    }
}

The class is used in a unit test like this:

var data = new NewUserData();

Hovering over NewUserData doesn't show me the docstring in IDE (Visual Studio). Is there a way to make this happen without moving the docstring down to the constructor?

答案1

得分: 1

"Found out one can achieve this with the inheritdoc tag and specify the class name as cref.

/// &lt;inheritdoc cref=&quot;NewUserData&quot;/&gt;
var data = new NewUserData();
```"

<details>
<summary>英文:</summary>

Found out one can achieve this with the inheritdoc tag and specify the class name as cref.

```csharp
/// &lt;inheritdoc cref=&quot;NewUserData&quot;/&gt;
var data = new NewUserData();

huangapple
  • 本文由 发表于 2023年4月19日 18:45:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76053598.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定