Exemplo n.º 1
0
        public void BuildAndPopulateAll <T>(T target, ICommandBuildingConventions conventions = null)
        {
            if (conventions == null)
            {
                conventions = _conventions;
            }

            ICommand instance = null;

            foreach (var property in GetCommandProperties(typeof(T)))
            {
                if (property.GetValue(target, null) == null)
                {
                    if (property.PropertyType == typeof(ICommand))
                    {
                        instance = BuildFromName <Command>(property.Name, conventions).GetInstance();
                    }
                    else
                    {
                        var builder = CreateCommandBuilderFor(property.PropertyType);
                        instance = (ICommand)builder.GetType().GetMethod("GetInstance").Invoke(builder, null);
                    }
                    property.SetValue(target, instance, null);
                }
            }
        }
Exemplo n.º 2
0
        CommandBuilder <TC> BuildFromName <TC>(string name, ICommandBuildingConventions conventions) where TC : ICommand
        {
            var builder = new CommandBuilder <TC>(_commandCoordinator, _conventions);

            builder.WithName(conventions.CommandName(name));
            return(builder);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of <see cref="CommandBuilder"/>
        /// </summary>
        /// <param name="commandCoordinator"><see cref="ICommandCoordinator"/> to use</param>
        public CommandBuilder(ICommandCoordinator commandCoordinator, ICommandBuildingConventions conventions)
        {
            _commandCoordinator = commandCoordinator;
            _conventions        = conventions;

            if (typeof(T) != typeof(Command) && typeof(T) != typeof(ICommand))
            {
                Name = conventions.CommandName(typeof(T).Name);
            }
        }
Exemplo n.º 4
0
#pragma warning disable 1591 // Xml Comments
        public ICommandBuilder <TC> BuildFrom <TC>(Expression <Func <TC> > property, ICommandBuildingConventions conventions = null) where TC : ICommand
        {
            if (conventions == null)
            {
                conventions = _conventions;
            }

            var propertyName = property.GetPropertyInfo().Name;
            var builder      = BuildFromName <TC>(propertyName, conventions);

            return(builder);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of <see cref="CommandFactory"/>
 /// </summary>
 /// <param name="commandCoordinator"><see cref="ICommandCoordinator"/> to use when handling commands</param>
 public CommandFactory(ICommandCoordinator commandCoordinator, ICommandBuildingConventions conventions)
 {
     _commandCoordinator = commandCoordinator;
     _conventions        = conventions;
 }