Exemple #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());
        }
Exemple #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)
                                     )));
        }
 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);
 }
 public int CompareTo(IMapValueRecord obj) => CompareTo(obj.Value);