public T Map(IDictionary <string, CommandLineArgument> arguments, T instance)
        {
            HashSet <CommandLineArgument> sharedArguments = new HashSet <CommandLineArgument>();

            foreach (var mapping in MappingList.FromType <T>())
            {
                if (mapping.IsOption())
                {
                    var wasSet = SetOptionValue(instance, mapping, arguments);
                    if (wasSet)
                    {
                        sharedArguments.Add(mapping.CommandLineArgument);
                        ValidateProperty(instance, mapping.PropertyInfo);

                        MappedCommandLineArgument?.Invoke(this, new MapperEventArgs(mapping.CommandLineArgument, mapping.PropertyInfo, instance));
                    }
                }
                else
                {
                    var wasSet = SetArgumentValue(instance, mapping, arguments);
                    if (wasSet)
                    {
                        sharedArguments.Add(mapping.CommandLineArgument);
                        ValidateProperty(instance, mapping.PropertyInfo);

                        MappedCommandLineArgument?.Invoke(this, new MapperEventArgs(mapping.CommandLineArgument, mapping.PropertyInfo, instance));
                    }
                }
            }

            CheckForUnmappedArguments(arguments, sharedArguments, instance);
            return(instance);
        }
Beispiel #2
0
 internal MappingInfo([NotNull] PropertyInfo propertyInfo, [NotNull] CommandLineAttribute commandLineAttribute, [NotNull] MappingList mappingList)
 {
     this.mappingList     = mappingList ?? throw new ArgumentNullException(nameof(mappingList));
     PropertyInfo         = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo));
     CommandLineAttribute = commandLineAttribute ?? throw new ArgumentNullException(nameof(commandLineAttribute));
 }