예제 #1
0
        public static ICollection <T> GetAnalogs <T>(this IMapValueRecord rec) where T : IMapRecord
        {
            if (rec == null || (string.IsNullOrWhiteSpace(rec.Value) && string.IsNullOrWhiteSpace(rec.Translation)))
            {
                return(new T[0]);
            }
            var rgxp = new Regex(rec.RegexCompareExpression(), RegexOptions.IgnoreCase);

            return(_ValuesDictionary.OfType <IMapValueRecord>().Where(v => rgxp.IsMatch(v.Value) || rgxp.IsMatch(v.Translation)).Except(new IMapValueRecord[] { rec }).OfType <T>().ToArray());
        }
예제 #2
0
        public static string RegexCompareExpression(this IMapValueRecord rec)
        {
            var vVal = rec.Value.Trim();
            var vTr  = rec.Translation?.Trim();

            return(string.Format(@"(?s)^\s*{0}\s*$", Regex.Escape(
                                     string.IsNullOrWhiteSpace(vVal) ?
                                     vTr :
                                     string.IsNullOrWhiteSpace(vTr) ?
                                     vVal :
                                     string.Format("{0}|{1}", vVal, vTr)
                                     )));
        }
예제 #3
0
 public IMapValueRecord FindNext(IMapValueRecord[] lst, string pattern, IMapValueRecord curr = null)
 {
     try
     {
         var rgxp = new Regex(pattern, RegexOptions.IgnoreCase, new System.TimeSpan(0, 0, 1));
         var idx  = FindNext(lst, rgxp, curr != null && (rgxp.IsMatch(curr.Value) || !rgxp.IsMatch(curr.Translation)) ? Array.IndexOf(lst, curr) + 1 : 0);
         if (idx > -1)
         {
             return(lst[idx]);
         }
     }
     catch
     {
     }
     return(curr);
 }
예제 #4
0
 public int CompareTo(IMapValueRecord obj) => CompareTo(obj.Value);