11namespace DendroDocs . Extensions ;
22
3+ /// <summary>
4+ /// Provides extension methods for working with collections of type descriptions, including type lookup,
5+ /// inheritance analysis, method invocation tracing, and member population.
6+ /// </summary>
37public static class IEnumerableTypeDescriptionExtensions
48{
9+ /// <summary>
10+ /// Finds the first type description with the specified full name.
11+ /// </summary>
12+ /// <param name="types">The collection of type descriptions to search.</param>
13+ /// <param name="typeName">The full name of the type to find.</param>
14+ /// <returns>The first type description with the specified name.</returns>
15+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="types"/> is <c>null</c>.</exception>
16+ /// <exception cref="InvalidOperationException">Thrown when no type with the specified name is found.</exception>
517 public static TypeDescription First ( this IEnumerable < TypeDescription > types , string typeName )
618 {
719 ArgumentNullException . ThrowIfNull ( types ) ;
820
921 return types . First ( t => string . Equals ( t . FullName , typeName , StringComparison . Ordinal ) ) ;
1022 }
1123
24+ /// <summary>
25+ /// Finds the first type description with the specified full name, or returns <c>null</c> if not found.
26+ /// </summary>
27+ /// <param name="types">The collection of type descriptions to search.</param>
28+ /// <param name="typeName">The full name of the type to find.</param>
29+ /// <returns>The first type description with the specified name, or <c>null</c> if not found.</returns>
30+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="types"/> is <c>null</c>.</exception>
1231 public static TypeDescription ? FirstOrDefault ( this IEnumerable < TypeDescription > types , string typeName )
1332 {
1433 ArgumentNullException . ThrowIfNull ( types ) ;
1534
1635 return types . FirstOrDefault ( t => string . Equals ( t . FullName , typeName , StringComparison . Ordinal ) ) ;
1736 }
1837
38+ /// <summary>
39+ /// Finds method bodies that match the specified method invocation.
40+ /// </summary>
41+ /// <param name="types">The collection of type descriptions to search.</param>
42+ /// <param name="invocation">The method invocation to match against.</param>
43+ /// <returns>A read-only list of method bodies that match the invocation. Returns an empty list if no matches are found.</returns>
44+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="types"/> is <c>null</c>.</exception>
1945 public static IReadOnlyList < IHaveAMethodBody > GetInvokedMethod ( this IEnumerable < TypeDescription > types , InvocationDescription invocation )
2046 {
2147 ArgumentNullException . ThrowIfNull ( types ) ;
@@ -29,6 +55,13 @@ public static IReadOnlyList<IHaveAMethodBody> GetInvokedMethod(this IEnumerable<
2955 return [ .. type . MethodBodies ( ) . Where ( invocation . MatchesMethod ) ] ;
3056 }
3157
58+ /// <summary>
59+ /// Recursively traces all method invocations that result from executing the specified invocation.
60+ /// </summary>
61+ /// <param name="types">The collection of type descriptions to search.</param>
62+ /// <param name="invocation">The initial method invocation to trace.</param>
63+ /// <returns>A read-only list of all invocations in the call chain, including the original invocation.</returns>
64+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="types"/> is <c>null</c>.</exception>
3265 public static IReadOnlyList < InvocationDescription > GetInvocationConsequences ( this IEnumerable < TypeDescription > types , InvocationDescription invocation )
3366 {
3467 ArgumentNullException . ThrowIfNull ( types ) ;
@@ -42,6 +75,13 @@ public static IReadOnlyList<InvocationDescription> GetInvocationConsequences(thi
4275 return consequences ;
4376 }
4477
78+ /// <summary>
79+ /// Gets all statements that result from executing the specified method invocation, including nested statements from called methods.
80+ /// </summary>
81+ /// <param name="types">The collection of type descriptions to search.</param>
82+ /// <param name="invocation">The method invocation to analyze.</param>
83+ /// <returns>A read-only list of all statements that result from the invocation, including the invocation itself.</returns>
84+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="types"/> is <c>null</c>.</exception>
4585 public static IReadOnlyList < Statement > GetInvocationConsequenceStatements ( this IEnumerable < TypeDescription > types , InvocationDescription invocation )
4686 {
4787 ArgumentNullException . ThrowIfNull ( types ) ;
@@ -55,6 +95,13 @@ public static IReadOnlyList<Statement> GetInvocationConsequenceStatements(this I
5595 return consequences ;
5696 }
5797
98+ /// <summary>
99+ /// Recursively traverses and expands complex statements (like switches and conditional statements) to include all nested statements.
100+ /// </summary>
101+ /// <param name="types">The collection of type descriptions to use for method resolution.</param>
102+ /// <param name="sourceStatement">The statement to traverse and expand.</param>
103+ /// <returns>A read-only list of statements with expanded nested structures. For simple statements, returns an empty list.</returns>
104+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="types"/> is <c>null</c>.</exception>
58105 public static IReadOnlyList < Statement > TraverseStatement ( this IEnumerable < TypeDescription > types , Statement sourceStatement )
59106 {
60107 ArgumentNullException . ThrowIfNull ( types ) ;
@@ -107,6 +154,12 @@ public static IReadOnlyList<Statement> TraverseStatement(this IEnumerable<TypeDe
107154 }
108155 }
109156
157+ /// <summary>
158+ /// Populates the inheritance hierarchy for all types by adding inherited base types recursively.
159+ /// This method modifies the BaseTypes collection of each type to include all inherited types from the inheritance chain.
160+ /// </summary>
161+ /// <param name="types">The collection of type descriptions to process.</param>
162+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="types"/> is <c>null</c>.</exception>
110163 public static void PopulateInheritedBaseTypes ( this IEnumerable < TypeDescription > types )
111164 {
112165 ArgumentNullException . ThrowIfNull ( types ) ;
@@ -141,6 +194,15 @@ private static void PopulateInheritedBaseTypes(this IEnumerable<TypeDescription>
141194 }
142195 }
143196
197+ /// <summary>
198+ /// Populates inherited members (fields, properties, methods, constructors, enum members, and events) from base types into derived types.
199+ /// This method adds non-private members from base types to derived types if they are not already present.
200+ /// </summary>
201+ /// <param name="types">The collection of type descriptions to process.</param>
202+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="types"/> is <c>null</c>.</exception>
203+ /// <remarks>
204+ /// This is a simplified inheritance implementation that does not handle complex scenarios like method overrides or hiding.
205+ /// </remarks>
144206 public static void PopulateInheritedMembers ( this IEnumerable < TypeDescription > types )
145207 {
146208 ArgumentNullException . ThrowIfNull ( types ) ;
0 commit comments