Skip to content

"help" crashes when mixing UsageAttribute with other Attributes #443

@ghost

Description

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();
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions