⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 brokenruleslist.cs

📁 改程序能够查询课程表
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Common.Utility.Validation
{
   /// <summary>
   /// A List of broken rules.
   /// </summary>
   [Serializable()]
   public class BrokenRulesList : BindingList<BrokenRule>
   {

      /// <summary>
      /// Returns the firstRule <see cref="BrokenRule" /> object
      /// corresponding to the specified property.
      /// </summary>
      /// <param name="property">The name of the property affected by the rule.</param>
      /// <returns>
      /// The firstRule BrokenRule object corresponding to the specified property, or null if 
      /// there are no rules defined for the property.
      /// </returns>
      public BrokenRule GetFirstBrokenRule(string property)
      {
         foreach (BrokenRule item in this)
            if (item.Property == property)
               return item;
         return null;
      }

      /// <summary>
      /// Internal contructor
      /// </summary>
      internal BrokenRulesList()
      {
         // limit creation to this assembly
      }

      /// <summary>
      /// Add a broken rule to the list
      /// </summary>
      /// <param name="rule"><see cref="ValidationRuleInfo"/> object containing the details about the rule.</param>
      internal void Add(ValidationRuleInfo rule)
      {
         Remove(rule);
         Add(new BrokenRule(rule));

      }

      /// <summary>
      /// Removes a broken rule from the list
      /// </summary>
      /// <param name="rule"><see cref="ValidationRuleInfo"/> object containing the details about the rule.</param>
      internal void Remove(ValidationRuleInfo rule)
      {
         
         for (int index = Count - 1; index >= 0; index--)
            if (this[index].RuleName == rule.RuleName)
            {
               RemoveAt(index);
               break;
            }

      }

		/// <summary>
      /// Returns a string containing all of the broken rule descriptions for the specified property.
      /// </summary>
      /// <param name="propertyName">The name of the property to get the errors for.</param>
      /// <returns>String of the error descriptions</returns>
      public string GetPropertyErrorDescriptions(string propertyName)
      {
         System.Text.StringBuilder errorDescription = new System.Text.StringBuilder();
         bool firstRule = true;
         foreach (BrokenRule item in this)
         {
            if (string.IsNullOrEmpty(propertyName) || item.Property.Equals(propertyName))
            {
               if (firstRule)
                  firstRule = false;
               else
                  errorDescription.Append(Environment.NewLine);

               errorDescription.Append(item.Description);
            }
         }

         return errorDescription.ToString();
      }

      /// <summary>
      /// Returns the description of each broken rule separated by a new line.
      /// </summary>
      public override string ToString()
      {
         return GetPropertyErrorDescriptions(null);
      }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -