commandline icon indicating copy to clipboard operation
commandline copied to clipboard

"help" crashes when mixing UsageAttribute with other Attributes

Open ghost opened this issue 8 years ago • 0 comments

When using the "Usage" attribute together with a 2nd one (e.g. ExcludeFromCoverage) like this:

[Usage]
[ExcludeFromCodeCoverage]
public static IEnumerable<Example> Examples ...

In this situation displaying "help" will cause an exception. The cause for that is likely fixed by this change:

src/CommandLine/Core/ReflectionExtensions.cs: L45

    public static Maybe<Tuple<PropertyInfo, UsageAttribute>> GetUsageData(this Type type)
    {
        return
            (from pi in type.FlattenHierarchy().SelectMany(x => x.GetTypeInfo().GetProperties())
                let attrs = pi.GetCustomAttributes(true)
                where attrs.OfType<UsageAttribute>().Any()
                select Tuple.Create(pi, (UsageAttribute)attrs.OfType<UsageAttribute>().First()))
                    .SingleOrDefault()
                    .ToMaybe();
    }

ghost avatar May 19 '17 10:05 ghost