Beispiel #1
0
        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);
        }
Beispiel #2
0
        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;
                }
            }
        }