Exemplo n.º 1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="BuildCapability" /> class.
        /// </summary>
        /// <param name="rule">The rule that provides the build functions.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="rule" /> parameter is <c>null</c>.</exception>
        public BuildCapability(ICreationRule rule)
        {
            rule = rule ?? throw new ArgumentNullException(nameof(rule));

            ImplementedByType = rule.GetType();
            SupportsCreate    = true;

            _createType      = (strategy, type, args) => rule.Create(strategy, type);
            _createProperty  = (strategy, propertyInfo, args) => rule.Create(strategy, propertyInfo);
            _createParameter = (strategy, parameterInfo, args) => rule.Create(strategy, parameterInfo);
            _populate        = (strategy, instance) =>
                               throw new NotSupportedException(
                                         $"{nameof(ICreationRule)} types do not support populating an instance.");
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Adds a new creation rule to the configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="rule">The rule.</param>
        /// <returns>The configuration.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="configuration" /> parameter is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="rule" /> parameter is <c>null</c>.</exception>
        public static IBuildConfiguration Add(this IBuildConfiguration configuration, ICreationRule rule)
        {
            configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));

            rule = rule ?? throw new ArgumentNullException(nameof(rule));

            configuration.CreationRules.Add(rule);

            return(configuration);
        }