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

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

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

问题

  1. /// <summary>
  2. /// 在这种情况下,用户是新加入群组的,但可能以前就存在。
  3. /// </summary>
  4. class NewUserData {
  5. public User user;
  6. // 更多数据字段在这里...
  7. public NewUserData(){
  8. // 在这里创建测试数据...
  9. }
  10. }
  1. var data = new NewUserData();

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

  1. <details>
  2. <summary>英文:</summary>
  3. I have a class to generate test data that I have documented with a docstring.
  4. ```csharp
  5. /// &lt;summary&gt;
  6. /// In this scenario the user is new to the group, but may have existed from before.
  7. /// &lt;/summary&gt;
  8. class NewUserData {
  9. public User user;
  10. // More data fields here ...
  11. public NewUserData(){
  12. // Creating test data here ...
  13. }
  14. }

The class is used in a unit test like this:

  1. 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.

  1. /// &lt;inheritdoc cref=&quot;NewUserData&quot;/&gt;
  2. var data = new NewUserData();
  3. ```"
  4. <details>
  5. <summary>英文:</summary>
  6. Found out one can achieve this with the inheritdoc tag and specify the class name as cref.
  7. ```csharp
  8. /// &lt;inheritdoc cref=&quot;NewUserData&quot;/&gt;
  9. 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:

确定