public IEnumerable <KeyValuePair <string, string> > Convert(MapiMap map, Dictionary <string, string> data) { var values = new List <KeyValuePair <string, string> >(); if (!data.ContainsKey(map.From) || map.Type.ToLower() != "split") { return(values); } var toSplits = map.To.Split('|'); Regex regex = new Regex(map.Meta); Match match = regex.Match(data[map.From]); if (match.Success) { for (int i = 0; i < toSplits.Length; i++) { values.Add(new KeyValuePair <string, string>(toSplits[i], match.Groups[i + 1].Value)); } } return(values); }
public IEnumerable <KeyValuePair <string, string> > Convert(MapiMap map, Dictionary <string, string> data) { if (data.ContainsKey(map.From)) { yield return(new KeyValuePair <string, string>(map.To, data[map.From])); } }
public static IMapiConverter GetConverter(MapiMap map) { switch (map.Type.ToLower()) { case "direct": return(new DirectMapiConverter()); case "split": return(new SplitMapiConverter()); default: return(null); } }
public void JustSomeRandomTest() { var converter = new SplitMapiConverter(); MapiMap map = new MapiMap("a", "split", "b|c", @"([\d|A-Z]*) (([A-Z|a-z| ]*) ([A-Z|a-z]*))"); Dictionary <string, string> from = new Dictionary <string, string> { { "trash", "more trash" }, { "a", "123 Main Street" }, { "blah", "blahdeblah" } }; IEnumerable <KeyValuePair <string, string> > result = converter.Convert(map, from); Assert.AreEqual(1, result.Count()); }