private static void SetOne(object obj, bool keyed, IConfBlock block, string key, int dotCount, ConfConverter converter) { var parts = key.Split('.'); var start = keyed ? dotCount + 1 : dotCount; for (var i = start; i < parts.Length; i++) { var propertyKey = parts[i]; var objectProperty = new ObjectProperty(obj, propertyKey, Cache, converter); if (objectProperty.Exists) { if (i == parts.Length - 1) { var item = objectProperty.Item; if (item != null && item.Exists) { item.SetValue(block, key); } else { objectProperty.SetValue(block, key); } break; } else { if (objectProperty.PropertyValue == null) { objectProperty.SetValue(block, string.Join(".", parts.Take(i + 1))); } var item = objectProperty.Item; if (item != null && item.Exists && (item.IndexExists == false || item.PropertyValue == null)) { item.SetValue(block, string.Join(".", parts.Take(i + 1))); } obj = item != null && item.Exists ? item.PropertyValue : objectProperty.PropertyValue; } } else { break; } } }
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); }
public override object ConvertFrom(IConfBlock conf, ITypeDescriptorContext context, CultureInfo culture, object value) { Param = conf; Value = value; return(Conversion); }
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 <KeyValuePair <string, T> > Indexed <T>(Func <string, T> factory, string collection, IEqualityComparer <string> comparer, IConfBlock conf) { if (null == factory) { throw new ArgumentNullException(nameof(factory)); } var coll = collection ?? typeof(T).Name; var dict = Pairs(coll, comparer, conf); var keys = dict.AllKeys; foreach (var key in keys) { var val = dict[key]; var cnf = new ConfContainer { Content = val }; var obj = factory(key); yield return(new KeyValuePair <string, T>(key, cnf.Configure(obj, ""))); } }
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 virtual object ConvertFrom(IConfBlock conf, ITypeDescriptorContext context, CultureInfo culture, object value) { return(base.ConvertFrom(context, culture, value)); }