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); } } }
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); }
/// <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); } }
#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); }
/// <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; }