コード例 #1
0
        /// <summary>
        /// Will create new instance of <see cref="IDynamicCommandBuilder"/>.
        /// </summary>
        /// <param name="name">Command name</param>
        /// <param name="strategy"><see cref="IDynamicCommandStrategy"/></param>
        /// <returns><see cref="IDynamicCommandBuilder"/></returns>
        protected IDynamicCommandBuilder CreateBuilder(string name, IDynamicCommandStrategy strategy, IViewModel viewModel)
        {
            IDynamicCommandBuilder builder = new DynamicCommandBuilder(name, strategy, viewModel);

            if (_defaultConfigure != null)
            {
                builder = _defaultConfigure(builder);
            }

            return(builder);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new instance of <see cref="DynamicCommandBuilder"/>.
        /// </summary>
        /// <param name="name">The name of the command.</param>
        /// <param name="baseStrategy">The base strategy to use for the command.</param>
        /// <param name="viewModel">The <see cref="IViewModel"/> that will own the newly created <see cref="IDynamicCommand"/>.</param>
        public DynamicCommandBuilder(string name, IDynamicCommandStrategy baseStrategy, IViewModel viewModel = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException($"'{nameof(name)}' cannot be null or empty", nameof(name));
            }

            Name         = name;
            ViewModel    = viewModel;
            BaseStrategy = baseStrategy ?? throw new ArgumentNullException(nameof(baseStrategy));
        }
コード例 #3
0
		/// <summary>
		/// Initializes a new instance of the <see cref="DynamicCommand"/> class.
		/// </summary>
		/// <param name="name">Command name</param>
		/// <param name="strategy"><see cref="IDynamicCommandStrategy"/></param>
		public DynamicCommand(string name, IDynamicCommandStrategy strategy)
		{
			Name = name;

			_strategy = strategy ?? throw new ArgumentNullException(nameof(strategy));

			_strategy.CanExecuteChanged += OnCanExecuteChanged;

			if (_diagnostics.IsEnabled("Created"))
			{
				_diagnostics.Write("Created", Name);
			}
		}
コード例 #4
0
        private static IDynamicCommandStrategy GetStrategy(IDynamicCommandStrategy baseStrategy, IList <DecoratorCommandStrategy> delegatingStrategies)
        {
            var strategy = baseStrategy;

            // We use 'Reverse' so that the first items in the builder wrap the ones added later on.
            foreach (var delegatingStrategy in delegatingStrategies.Reverse())
            {
                // Stitch up all the delegating strategies together.
                delegatingStrategy.InnerStrategy = strategy;
                strategy = delegatingStrategy;
            }

            return(strategy);
        }