Skip to content

Commit

Permalink
feat(tooling): resolve most derived task type
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed Dec 3, 2024
1 parent 6bf2e19 commit b100dfb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions source/Nuke.Tooling/ToolTasks.Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,14 @@ protected virtual IProcess StartProcess(
logger,
outputFilter);
}

public static T Resolve<T>()
where T : ToolTasks
{
var applicableTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
.Where(x => x.IsAssignableTo(typeof(T)))
.OrderByDescending(x => x.Descendants(x => x.BaseType).Count());
var mostDerivedType = applicableTypes.First();
return mostDerivedType.CreateInstance<T>();
}
}

0 comments on commit b100dfb

Please sign in to comment.