public CommandParameterAnalysis(InputCommand command)
        {
            // get defintion

            var definition = command.GetType().DescribeInputCommand();

            // get parameters in set - all parameters available for the active set

            ParametersInSet = definition.Parameters;
            if (!string.IsNullOrWhiteSpace(command.ActiveParameterSet))
            {
                ParametersInSet = ParametersInSet
                                  .Where(p => string.IsNullOrEmpty(p.ParameterSet) ||
                                         p.ParameterSet.Equals(command.ActiveParameterSet)).ToList();
            }

            // get missing required parameters in set - where a complete parameter node is missing for a required parameter in the current set

            MissingRequiredParameters = ParametersInSet.Where(p => p.IsRequired &&
                                                              p.PropertyInfo.GetValue(command) == null).ToList();

            // get superflous parameters - where at least a named parameter switch is defined for a parameter that is not included in the current set

            SuperflousParameters = definition.Parameters.Where(p => p.PropertyInfo.GetValue(command) != null &&
                                                               !ParametersInSet.Contains(p)).ToList();

            // get available parameters in set - all remaining parameters where at least a named parameter switch has not been defined for the current set

            AvailableParameters = definition.Parameters.Where(p => p.PropertyInfo.GetValue(command) == null &&
                                                              ParametersInSet.Contains(p)).ToList();

            // get available switches

            AvaliableSwitches = definition.Switches.Where(s => !((SwitchParameter)s.PropertyInfo.GetValue(command)).IsPresent).ToList();
        }
示例#2
0
 public void Map(InputCommand inputCommand)
 {
     foreach (var propertyInfo in inputCommand.GetType().GetProperties())
     {
         if (propertyInfo.GetValue(inputCommand) != null)
         {
             var targetProperty = GetType()
                                  .GetProperty(propertyInfo.Name,
                                               BindingFlags.IgnoreCase |
                                               BindingFlags.Instance |
                                               BindingFlags.Public);
             if (targetProperty != null && targetProperty.PropertyType == propertyInfo.PropertyType)
             {
                 targetProperty.SetValue(this,
                                         propertyInfo.GetValue(inputCommand));
             }
         }
     }
 }