作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
C# 9 记录有一个简短的形式,如下所示:
public record Car(int CarId, int Cylinders, string Make, string Model);
如何将文档注释添加到记录的属性中?请注意,这与
this 不同关于长格式的其他问题。
最佳答案
正确的方法看起来就像这样简单:
/// <summary>
/// Represents a car.
/// </summary>
/// <param name="CarId">The id of the car.</param>
/// <param name="Cylinders">The number of cylinders.</param>
/// <param name="Make">The make of the car.</param>
/// <param name="Model">The model of the car.</param>
public record Car(int CarId, int Cylinders, string Make, string Model);
当您创建此记录的新实例(即
new Car(...)
将为您提供不同参数的信息)时,这在 IDE 的 IntelliSense(VSCode 上的测试)中确实有效。
<GenerateDocumentationFile>true</GenerateDocumentationFile>
,则编译器的警告系统本身似乎存在问题。在您的
.csproj
中启用.对于每个参数,您将获得以下警告对:
warning CS1572: XML comment has a param tag for 'CarId', but there is no parameter by that name
warning CS1573: Parameter 'CarId' has no matching param tag in the XML comment for 'Car.Car(int, int, string, string)' (but other parameters do)
所以它确实有效,但是编译器提示参数没有被记录,并且有一个不存在的参数的文档。
关于c# - 如何向 C# 9 记录添加注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64934212/
我是一名优秀的程序员,十分优秀!