.Net核心允许您使用[DisallowNull]修饰属性,以告知编译器不允许代码将属性设置为null,即使属性本身已声明允许这样做。例如: public sealed class Test [DisallowNull] public string?Text { get; set; }test.Text = null; // Warning
我有一个DTO,它是通过读取DynamoDB表来填充的。比如说现在看起来是这样的:{
public string Id { get; set; } // PK so technically cannot be null我宁愿避免使用非参数的构造函数,因为这与Dynamo中的ORM (以及其他构造函数)有很大关系。编写public string Id { get; set; } = "";对我来说似乎很奇怪,因为Id是一个