CSLA:对于每个特定类型的属性而不必为每个属性手动添加它,是否有可能为businessRule.add()添加它吗?

发布于 2025-02-13 08:42:25 字数 418 浏览 0 评论 0原文

我创建了一个规则,用于检查日期时间是否有效。我想将其添加为每个DateTime属性的businesrule,以检查输入的用户输入是否有效,否则会发出警告。

现在,我必须在每个DateTime属性中添加每个类型属性的业务插曲,

BusinessRules.AddRule(new DateValidRule(BornDateProperty) { Severity = RuleSeverity.Warning });
BusinessRules.AddRule(new DateValidRule(LegitimationDateProperty) { Severity = RuleSeverity.Warning });
....

这将需要为Type DateTime的每个属性手动完成每个类。

有更好的方法可以做到这一点吗?

I have created a rule for checking if a DateTime is valid. I want to add this as a BusinesRule for every single DateTime Property to checks if the user input entered is valid and else give a warning.

Now I would have to add in every class the businessrules for each DateTime Property manually

BusinessRules.AddRule(new DateValidRule(BornDateProperty) { Severity = RuleSeverity.Warning });
BusinessRules.AddRule(new DateValidRule(LegitimationDateProperty) { Severity = RuleSeverity.Warning });
....

This will be needed to be done manually for every single class for every single Property of type DateTime.

Is there a better more efficient way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2025-02-20 08:42:25

是的,您可以使用fieldmanager属性访问注册属性列表,并循环通过它们。

      foreach (var property in FieldManager.GetRegisteredProperties().Where(r=>r.Type == typeof(DateTime)))
      {
        BusinessRules.AddRule(new DateValidRule(property) { Severity = RuleSeverity.Warning });
      }

Yes, you can use the FieldManager property to access the list of registered properties and loop through them.

      foreach (var property in FieldManager.GetRegisteredProperties().Where(r=>r.Type == typeof(DateTime)))
      {
        BusinessRules.AddRule(new DateValidRule(property) { Severity = RuleSeverity.Warning });
      }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文