Skip to content

Inverse order of FlatternHierarchy #506

Closed
@rlsf

Description

@rlsf

Hello,
The current implementation of FlatternHierarchy function returns the current type first.
This in turn causes the help routine to print the options/values attributes of the current type before inherited types.
From my point of view, however, the current type should be returned last, so common options/values which are declared in the inherited class will appear first in the help message.

example:

public class CliBase
{
  [Option("opt1")]
  public string Opt1 { get; set; }
}

public class CliCommand : CliBase
{
  [Option("opt2")]
  public string Opt2 { get; set; }
}

printing the help information for CliCommand, will result in opt2 being printed before opt1, while i expect the reverse order, so any new command inheriting from CliBase will have opt1 printed first.

the actual code change is in FlattenHierarchy method, instead of current implementation, use this one:

private static IEnumerable<Type> FlattenHierarchy(this Type type)
{
	if (type == null)
	{
		yield break;
	}

	foreach (var @interface in type.SafeGetInterfaces())
	{
		yield return @interface;
	}
	foreach (var @interface in FlattenHierarchy(type.BaseType))
	{
		yield return @interface;
	}
	yield return type;
}

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