|
| 1 | +using System.Diagnostics; |
1 | 2 | using System.Reflection; |
2 | 3 | using RT.Internal; |
3 | 4 | using RT.PostBuild; |
@@ -457,7 +458,7 @@ private static object parseCommandLine(string[] args, Type type, int i, Func<Con |
457 | 458 | { |
458 | 459 | missingMandatories.Remove(field); |
459 | 460 | positionals.RemoveAt(0); |
460 | | - foreach (var subclass in field.FieldType.Assembly.GetTypes().Where(t => !t.IsAbstract && t.IsSubclassOf(field.FieldType))) |
| 461 | + foreach (var subclass in allTypes().Where(t => !t.IsAbstract && t.IsSubclassOf(field.FieldType))) |
461 | 462 | if (subclass.GetCustomAttributes<CommandNameAttribute>().First().Names.Any(c => c.Equals(args[i], StringComparison.OrdinalIgnoreCase))) |
462 | 463 | { |
463 | 464 | field.SetValue(ret, parseCommandLine(args, subclass, i + 1, helpProcessor)); |
@@ -518,6 +519,8 @@ private static object parseCommandLine(string[] args, Type type, int i, Func<Con |
518 | 519 | return ret; |
519 | 520 | } |
520 | 521 |
|
| 522 | + private static IEnumerable<Type> allTypes() => AppDomain.CurrentDomain.GetAssemblies().SelectMany(asm => asm.GetTypes()); |
| 523 | + |
521 | 524 | private static bool convertStringAndSetField(string value, object cmdLineObject, FieldInfo field) |
522 | 525 | { |
523 | 526 | object result; |
@@ -545,7 +548,7 @@ private static Func<int, ConsoleColoredString> getHelpGenerator(Type type, Func< |
545 | 548 |
|
546 | 549 | var helpString = new List<ConsoleColoredString>(); |
547 | 550 | var commandNameAttr = type.GetCustomAttributes<CommandNameAttribute>().FirstOrDefault(); |
548 | | - string commandName = commandNameAttr == null ? Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) : "... " + commandNameAttr.Names.OrderByDescending(c => c.Length).First(); |
| 551 | + string commandName = commandNameAttr == null ? Process.GetCurrentProcess().ProcessName : "... " + commandNameAttr.Names.OrderByDescending(c => c.Length).First(); |
549 | 552 |
|
550 | 553 | // |
551 | 554 | // ## CONSTRUCT THE “USAGE” LINE |
@@ -706,7 +709,7 @@ private static bool createParameterHelpRow(ref int row, TextTable table, FieldIn |
706 | 709 | else if (field.FieldType.IsDefined<CommandGroupAttribute>()) |
707 | 710 | { |
708 | 711 | int origRow = row; |
709 | | - foreach (var ty in field.FieldType.Assembly.GetTypes() |
| 712 | + foreach (var ty in allTypes() |
710 | 713 | .Where(t => t.IsSubclassOf(field.FieldType) && t.IsDefined<CommandNameAttribute>() && !t.IsAbstract && !t.IsDefined<UndocumentedAttribute>()) |
711 | 714 | .OrderBy(t => t.GetCustomAttributes<CommandNameAttribute>().First().Names.MinElement(c => c.Length))) |
712 | 715 | { |
@@ -919,7 +922,7 @@ private static void postBuildStep(IPostBuildReporter rep, Type commandLineType, |
919 | 922 | rep.Error($"{commandLineType.FullName}.{field.Name}: CommandGroup fields must be declared [IsPositional].", "class " + commandLineType.Name, field.Name); |
920 | 923 |
|
921 | 924 | // The class must have at least two subclasses with a [CommandName] attribute |
922 | | - var subclasses = field.FieldType.Assembly.GetTypes().Where(t => !t.IsAbstract && t.IsSubclassOf(field.FieldType)); |
| 925 | + var subclasses = allTypes().Where(t => !t.IsAbstract && t.IsSubclassOf(field.FieldType)); |
923 | 926 | if (!subclasses.Any()) |
924 | 927 | rep.Error($"{commandLineType.FullName}.{field.Name}: The CommandGroup class type must have at least one non-abstract derived class with the [CommandName] attribute.", "class " + field.FieldType.Name); |
925 | 928 |
|
|
0 commit comments