Wou*_*tte 1 c# code-documentation
假设我有这门课
public sealed class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string DisplayName => $"{FirstName} {LastName}";
}
Run Code Online (Sandbox Code Playgroud)
我想记录该DisplayName财产。
/// <summary>
/// A space seperated string of the FirstName and LastName
/// </summary>
public string DisplayName => $"{FirstName} {LastName}";
Run Code Online (Sandbox Code Playgroud)
但我现在的问题是,如果我将属性重命名LastName为FamilyName. 我的代码当然仍然可以编译,但我的文档将引用不存在的属性。
有没有一种方法可以像这种伪语法一样在属性DisplayName中引用实际属性LastName。
/// <summary>
/// A space seperated string of the <prop=FirstName> and <prop=LastName>
/// </summary>
Run Code Online (Sandbox Code Playgroud)
这样重构我的代码也会重构文档或者编译器至少会给出警告或者可能是错误?
使用<see>带有代码引用属性 ( cref) 的 -tag:
/// <summary>
/// A space seperated string of the <see cref="FirstName" /> and <see cref="LastName" />
/// </summary>
Run Code Online (Sandbox Code Playgroud)
您还可以通过适当地限定其他类的成员来引用它们,例如
/// <summary>
/// A space seperated string of the <see cref="AnotherClass.FirstName" /> and <see cref="MyClass.LastName" />
/// </summary>
Run Code Online (Sandbox Code Playgroud)
或者还有一种方法:
/// <summary>
/// A space seperated string of the <see cref="MyMethod" /> and <see cref="MethodWithOverloads(string, int, Type)" />
/// </summary>
Run Code Online (Sandbox Code Playgroud)