示例#1
0
 /// <summary>
 ///     Copies the value of an element.
 /// </summary>
 /// <typeparam name="TElement">
 ///     The type of the element to copy.
 /// </typeparam>
 /// <param name="implementation">
 ///     The details of the implementation for which to make a copy.
 /// </param>
 /// <param name="value">
 ///     The value to copy.
 /// </param>
 /// <param name="parent">
 ///     The parent object to which cloned configuration objects will belong.
 /// </param>
 /// <param name="configurationRoot">
 ///     The configuration root from which cloned configuration objects are to be populated.
 /// </param>
 /// <returns>
 ///     The newly copied element.
 /// </returns>
 public TElement CopyValue <TElement>(IImplementation implementation, TElement value, IConfigurationParent parent, IConfigurationRoot configurationRoot)
 {
     if (ReferenceEquals(value, null))
     {
         return(default !);
 public ConfigurationObjectMock(IPropertyDef propertyDef, IConfigurationRoot configurationRoot, IConfigurationParent parent, ConfigurationObjectSettings settings) : base(propertyDef, configurationRoot, parent, settings, System.Array.Empty <IConfigurationObjectValidator <IRootElement> >())
 {
 }
示例#3
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();
            }
        }