internal FlagDefinition(CallFlagAttribute attribute, ParameterInfo param) { if (!param.HasDefaultValue) { throw new ArgumentException($"The parameter {param} does not have a default value."); } DefaultValue = param.DefaultValue; ShortKey = attribute.ShortKey; LongKey = attribute.LongKey; Description = attribute.Description; Type = param.ParameterType; RequiresInput = Type != typeof(bool); Parameter = param; ParamName = NameAttribute.GetFor(param); }
private ArgumentInfo(ParameterInfo parameter, CallInfo call, bool useDefault) { Parameter = parameter; UseDefault = useDefault; IsDense = DenseAttribute.ExistsOn(parameter); Type = Parameter.ParameterType; DefaultValue = Parameter.DefaultValue; IsRawArgument = RawArgumentsAttribute.ExistsOn(parameter); HasDefaultValue = Parameter.HasDefaultValue; Name = NameAttribute.GetFor(Parameter); Parent = call; Flag = CallFlagAttribute.GetFor(Parameter); if (IsDense && Flag != null) { throw new InvalidOperationException("Cannot have a dense flag parameter"); } }
internal static IEnumerable <ArgumentInfo[]> BuildPermetations(CallInfo call) { var parameters = call.Method.GetParameters().TakeWhile(p => !CallFlagAttribute.ExistsOn(p)); var required = parameters.Where(p => !p.HasDefaultValue); var optional = parameters.Where(p => p.HasDefaultValue); var requiredMask = Enumerable.Range(0, required.Count()) .Select(v => true) .ToArray(); foreach (var optionalMask in IEnumerableUtil.BooleanMask(optional.Count())) { var fullMask = requiredMask.Concat(optionalMask).ToArray(); var args = parameters.Select((p, i) => new ArgumentInfo(p, call, !fullMask[i])).ToArray(); if (args.Count(a => a.IsDense) <= 1) { yield return(args); } } }