Skip to content

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

@ericnewton76

Description

@ericnewton76

Issue by LarsWeuste
Friday May 19, 2017 at 10:47 GMT
Originally opened as gsscoder/commandline#443


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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions