Page tree
Skip to end of metadata
Go to start of metadata

给属性添加校验,可以避免用户填写不支持的数据,减少开发不必要的错误处理逻辑。

1.属性必填

    1. 通过标注RequiredAttitude支持属性必填

      using GrapeCity.Forguncy.Commands;
      using GrapeCity.Forguncy.Plugin;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      
      namespace MyPlugin
      {
          [Icon("pack://application:,,,/MyPlugin;component/Resources/Icon.png")]
          [Designer("MyPlugin.Designer.MyPluginCommandDesigner, MyPlugin")]
          public class MyPluginCommand : Command
          {
              [Required]
              public string Name { get; set; }
          }
      }


    2. 效果:

2.校验长度

    1. 通过MaxLengthAttribute和MinLengthAttribute支持长度校验。

      using GrapeCity.Forguncy.Commands;
      using GrapeCity.Forguncy.Plugin;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      
      namespace MyPlugin
      {
          [Icon("pack://application:,,,/MyPlugin;component/Resources/Icon.png")]
          [Designer("MyPlugin.Designer.MyPluginCommandDesigner, MyPlugin")]
          public class MyPluginCommand : Command
          {
              [MaxLength(6)]
              [MinLength(1)]
              public string Name { get; set; }
          }
      }


    2. 效果:
  • No labels