We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在构造时实体中未被初始化的属性可能需要一种诊断分析器
假如开发者需要落实
这样的规则
这种情况下 编译器,无法协助,提示,使用StudentNumber之前,先检查StudentNumberAssigned
可能需要一种 诊断分析器(或者类似),来进行提示
(假设,开发者不落实上述规则,改使用,可空引用类型和值类型,编译器,反而会,帮助提示,先检查是否为null)
以下,是一种可能的方案的大概展示
public class Student { //学号 [InitializationCheckRequiredAttribute(nameof(StudentNumberAssigned))] public string StudentNumber { get; private set; } = "0"; //已经被分配学号 public bool StudentNumberAssigned { get; private set; } } /* * 一个Attribute * 用于让 自定义的 诊断分析器 知道 * 此属性的值 可能未被初始化 * 应该先读取 一个 bool 属性 来判断 此属性的值 是否 已经被初始化 */ public class InitializationCheckRequiredAttribute : Attribute { public InitializationCheckRequiredAttribute(string propertyToCheck) { } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
标题
在构造时实体中未被初始化的属性可能需要一种诊断分析器
情况描述
假如开发者需要落实
这样的规则
这种情况下
编译器,无法协助,提示,使用StudentNumber之前,先检查StudentNumberAssigned
建议
可能需要一种
诊断分析器(或者类似),来进行提示
(假设,开发者不落实上述规则,改使用,可空引用类型和值类型,编译器,反而会,帮助提示,先检查是否为null)
以下,是一种可能的方案的大概展示
The text was updated successfully, but these errors were encountered: