Пример #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ConfigurationObjectBase{TInterface}" /> class. This is the
        ///     interface used when creating the root instance for the service collection.
        /// </summary>
        /// <param name="propertyDef">
        ///     The definition of the property defined by this object. This can be <see lang="null" /> if this object is
        ///     the root of the hierarchy.
        /// </param>
        /// <param name="configurationRoot">
        ///     The configuration root from which to read and write values.
        /// </param>
        /// <param name="parent">
        ///     The parent object to which this one belongs. <see langword="null" /> if this is a root object.
        /// </param>
        /// <param name="settings">
        ///     The settings used to control how configuration objects are created and the features they support.
        /// </param>
        /// <param name="validators">
        ///     The validators that can be applied to configuration objects of this type.
        /// </param>
        protected ConfigurationObjectBase(IPropertyDef?propertyDef, IConfigurationRoot configurationRoot, IConfigurationParent parent, ConfigurationObjectSettings settings, IEnumerable <IConfigurationObjectValidator <TInterface> > validators) : base(propertyDef,
                                                                                                                                                                                                                                                          ServiceCollectionExtensions.GetConfigurationObjectDefinition(typeof(TInterface), settings), configurationRoot, parent)
        {
            _validators = validators?.ToArray() ?? Array.Empty <IConfigurationObjectValidator <TInterface> >();

            DisablePropertyChangedEvents();
            try
            {
                foreach (var value in Values)
                {
                    if (value.PropertyDef.HasDefaultValue)
                    {
                        value.Value = value.PropertyDef.DefaultValue;
                        value.Saved();
                    }
                }
            }
            finally
            {
                EnablePropertyChangedEvents();

                Validate();
            }
        }