private static NameValueCollection Pairs(string collection, IEqualityComparer <string> comparer, IConfBlock conf) { if (null == conf) { throw new ArgumentNullException(nameof(conf)); } var normC = Key.Normalize(collection); var count = conf.ItemCount(); var items = new NameValueCollection(new EqualityWrapper(comparer)); for (var i = 0; i < count; i++) { var confItem = conf.Item(i); var thisItem = new Item(confItem.NormalizedKey); if (thisItem.Collection != normC) { continue; } var indx = thisItem.Index; var rest = thisItem.Rest; var valu = confItem.OriginalValue; items[indx] += $"{rest} = {valu}" + Environment.NewLine; } return(items); }
public static IEnumerable <T> All <T>(Func <T> factory, string collection, IEqualityComparer <string> comparer, IConfBlock conf) { if (null == factory) { throw new ArgumentNullException(nameof(factory)); } if (null == conf) { throw new ArgumentNullException(nameof(conf)); } var normK = Key.Normalize(collection ?? typeof(T).Name); var count = conf.ItemCount(); var items = new HashSet <string>(comparer); for (var i = 0; i < count; i++) { var confItem = conf.Item(i); var thisItem = new Item(confItem.NormalizedKey); if (thisItem.Collection != normK) { continue; } items.Add(thisItem.Name); } foreach (var item in items) { yield return(conf.Configure(factory(), item)); } }
public static object SetAll(object obj, IConfBlock block, string key, ConfConverter converter) { var normKey = Key.Normalize(key); var noKey = normKey == ""; var dotCount = key.Count(c => c == '.'); var itemCount = block.ItemCount(); for (var i = 0; i < itemCount; i++) { var item = block.Item(i); if (item.NormalizedKey.StartsWith(normKey + ".") || noKey) { SetOne(obj, !noKey, block, item.NormalizedKey, dotCount, converter); } } return(obj); }