public bool IsValidUsage(IEnumerable <ITokenHandler> handlers) { var actualArgs = handlers.OfType <Argument>(); if (actualArgs.Count() != Arguments.Count()) { return(false); } if (!Arguments.All(x => actualArgs.Contains(x))) { return(false); } var flags = handlers.Where(x => !(x is Argument)); return(flags.All(x => ValidFlags.Contains(x))); }
public List <string> SetAndValidate(string[] inputs) { int i = 0; List <string> errors = new List <string>(); if (inputs.Length == 0) { return(errors); // which will be empty } for (i = 0; i < inputs.Length; i++) { bool exists = ValidFlags.TryGetValue(inputs[i], out Parameter parameter); if (!exists) { // // I always hate it when I pass in a bunch of parameters and have more than 1 wrong. // you get an error for the first one, fix it, try again and get the error for the second. // and so on...so we'll go through all of them and tell the user *all* the params that are bad errors.Add($"Bad Parameter {inputs[i]}"); } else { if (parameter.RequiresInput) { i++; parameter.Value = inputs[i]; } else { parameter.Value = "true"; // would have been nice to make this a template, but you can't have a type <T> in a Dictionary... } SetFlags[parameter.Name] = parameter; // I loop over these in main(), so it is important that it only have the name } } return(errors); }