protected override void OnBind()
        {
            base.OnBind();

            Debug.Assert(NotifyObject != null);
            propertyConfigMap.Clear();
            foreach (var x in NotifyPropertyMap.Values)
            {
                var transfedName = ObjectNamedCreator.NameTransfer.Transfer(NotifyObject, x.PropertyInfo.Name);

                var name = string.IsNullOrEmpty(transfedName) ? x.PropertyInfo.Name : transfedName;
                x.Name = name;
                Debug.Assert(!string.IsNullOrEmpty(name));

                if (Configuration is IConfigurationSection section)
                {
                    var targetName = ConfigurationPath.Combine(section.Path, name);
                    propertyConfigMap.Add(targetName, x);
                }
                else
                {
                    propertyConfigMap.Add(name, x);
                }

                if (x.PropertyInfo.PropertyType.GetInterface(INotifyPropertyChangedTypeName) != null)
                {
                    var val = propertyVisitor.GetValue(NotifyObject, x.PropertyInfo);
                    if (val != null)
                    {
                        if (x.BindBox != null)
                        {
                            x.BindBox.Dispose();
                        }
                        x.BindBox = CreatePropertyBindBox(val, x.PropertyInfo);
                        x.BindBox.Bind();
                    }
                }
            }
            NotifyObject.PropertyChanged += OnPropertyChanged;
        }
Exemple #2
0
 /// <summary>
 /// Gets a configuration sub-section with the specified key.
 /// </summary>
 /// <param name="key">The key of the configuration section.</param>
 /// <returns>The <see cref="IConfigurationSection"/>.</returns>
 /// <remarks>
 ///     This method will never return <c>null</c>. If no matching sub-section is found with the specified key,
 ///     an empty <see cref="IConfigurationSection"/> will be returned.
 /// </remarks>
 public IConfigurationSection GetSection(string key) => _root.GetSection(ConfigurationPath.Combine(Path, key));
 private void ExitContext()
 {
     _context.Pop();
     _currentPath = ConfigurationPath.Combine(_context.Reverse());
 }
 private void EnterContext(string context)
 {
     _context.Push(context);
     _currentPath = ConfigurationPath.Combine(_context.Reverse());
 }
        /// <summary>
        /// Gets the immediate children sub-sections of configuration root based on key.
        /// </summary>
        /// <param name="root">Configuration from which to retrieve sub-sections.</param>
        /// <param name="path">Key of a section of which children to retrieve.</param>
        /// <returns>Immediate children sub-sections of section specified by key.</returns>
        internal static IEnumerable <IConfigurationSection> GetChildrenImplementation(this IConfigurationRoot root, string?path)
        {
            using ReferenceCountedProviders? reference = (root as ConfigurationManager)?.GetProvidersReference();
            IEnumerable <IConfigurationProvider> providers = reference?.Providers ?? root.Providers;

            IEnumerable <IConfigurationSection> children = providers
                                                           .Aggregate(Enumerable.Empty <string>(),
                                                                      (seed, source) => source.GetChildKeys(seed, path))
                                                           .Distinct(StringComparer.OrdinalIgnoreCase)
                                                           .Select(key => root.GetSection(path == null ? key : ConfigurationPath.Combine(path, key)));

            if (reference is null)
            {
                return(children);
            }
            else
            {
                // Eagerly evaluate the IEnumerable before releasing the reference so we don't allow iteration over disposed providers.
                return(children.ToList());
            }
        }