Skip to content

Commit 86ab68f

Browse files
committed
Add async methods for C# source code retrieval
Introduce `FindCSharpSourceCodeAsync` methods in `IVsProjectActions`, `IVsProjectFolderActions`, `VsProject`, and `VsProjectFolder` for searching C# source code files with customizable criteria. Add new classes `CsSearchContainer` and `CsSourceSearchCriteria` to model search results and criteria. Update using directives for integration.
1 parent 7360e34 commit 86ab68f

File tree

6 files changed

+224
-0
lines changed

6 files changed

+224
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.Immutable;
4+
using System.Text;
5+
6+
namespace CodeFactory.WinVs.Models.CSharp
7+
{
8+
/// <summary>
9+
/// Data model that represents a summary of a C# container (class, interface, structure, etc.) for search results.
10+
/// </summary>
11+
public class CsSearchContainer
12+
{
13+
/// <summary>
14+
/// The namespace the C# cntainer is defined in.
15+
/// </summary>
16+
public string Namespace { get; init; }
17+
18+
/// <summary>
19+
/// Gets the name of the container associated with the current instance.
20+
/// </summary>
21+
public string Name { get; init; }
22+
23+
/// <summary>
24+
/// The security scope of the container represented by this instance.
25+
/// </summary>
26+
CsSecurity Security { get; init; } = CsSecurity.Unknown;
27+
28+
/// <summary>
29+
/// Gets the type of the container represented by this instance.
30+
/// </summary>
31+
public CsContainerType ContainerType { get; init; } = CsContainerType.Unknown;
32+
33+
/// <summary>
34+
/// Flag that determines if this container has a generic type definition.
35+
/// </summary>
36+
public bool IsGenericContainer { get; init; } = false;
37+
38+
/// <summary>
39+
/// List of the generic parameters defined for the container.
40+
/// </summary>
41+
public IReadOnlyList<CsGenericParameter> GenericParameters { get; init; } = ImmutableList<CsGenericParameter>.Empty;
42+
43+
/// <summary>
44+
/// Flag that determines if the container has strong types defined in its generic parameters.
45+
/// </summary>
46+
public bool HasStrongTypesInGenerics { get; init; } = false;
47+
48+
/// <summary>
49+
/// List of the generic types defined for the container.
50+
/// </summary>
51+
public IReadOnlyList<CsType> GenericTypes { get; init; } = ImmutableList<CsType>.Empty;
52+
53+
/// <summary>
54+
/// Flag that determines if the container has a base class defined.
55+
/// </summary>
56+
public bool HasBaseClass { get; init; } = false;
57+
58+
/// <summary>
59+
/// Flag that determines if the container inherits from any interfaces.
60+
/// </summary>
61+
public bool HasInheritedInterfaces { get; init; } = false;
62+
63+
/// <summary>
64+
/// Flag that determines if the container has any attributes defined.
65+
/// </summary>
66+
public bool HasAttributes { get; init; } = false;
67+
68+
/// <summary>
69+
/// List of the attributes defined for the container.
70+
/// </summary>
71+
public IReadOnlyList<CsAttribute> Attributes { get; init; } = ImmutableList<CsAttribute>.Empty;
72+
73+
/// <summary>
74+
/// Flag that determines if the container has any fields defined.
75+
/// </summary>
76+
public bool HasFields { get; init; } = false;
77+
78+
/// <summary>
79+
/// Flag that determines if the container has any properties defined.
80+
/// </summary>
81+
public bool HasProperties { get; init; } = false;
82+
83+
/// <summary>
84+
/// Flag that determines if the container has any methods defined.
85+
/// </summary>
86+
public bool HasMethods { get; init; } = false;
87+
88+
/// <summary>
89+
/// Flag that determines if the container has any events defined.
90+
/// </summary>
91+
public bool HasEvents { get; init; } = false;
92+
93+
/// <summary>
94+
/// Flag that determines if the container has any constructors defined.
95+
/// </summary>
96+
public bool HasConstructors { get; init; } = false;
97+
98+
}
99+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
6+
namespace CodeFactory.WinVs.Models.CSharp
7+
{
8+
/// <summary>
9+
/// Represents a set of search criteria for locating specific elements within a c# source code file.
10+
/// </summary>
11+
/// <remarks>This class provides a collection of customizable search predicates that can be used to filter
12+
/// and locate various elements within a source code container, such as methods, properties, fields, events,
13+
/// constructors, inherited interfaces, and base classes. Each predicate allows the caller to define specific
14+
/// conditions for the search, enabling flexible and precise queries.</remarks>
15+
public class CsSourceSearchCriteria
16+
{
17+
18+
/// <summary>
19+
/// Stores the search criteria for searching for a specific container in the source code.
20+
/// </summary>
21+
public Func<CsSearchContainer, bool> ContainerSearch { get; init; } = null;
22+
23+
/// <summary>
24+
/// Stores the search criteria for searching for a specific interface in the container.
25+
/// </summary>
26+
public Func<IReadOnlyList<CsInterface>, bool> InheritedInterfacesSearch { get; init; } = null;
27+
28+
/// <summary>
29+
/// Stores the search criteria for searching methods in the container.
30+
/// </summary>
31+
public Func<IReadOnlyList<CsMethod>, bool> MethodsSearch { get; init; } = null;
32+
33+
/// <summary>
34+
/// Stores the search criteria for searching properties in the container.
35+
/// </summary>
36+
public Func<IReadOnlyList<CsProperty>, bool> PropertiesSearch { get; init; } = null;
37+
38+
/// <summary>
39+
/// Stores the search criteria for searching fields in the container.
40+
/// </summary>
41+
public Func<IReadOnlyList<CsField>, bool> FieldsSearch { get; init; } = null;
42+
43+
/// <summary>
44+
/// Stores the search criteria for searching events in the container.
45+
/// </summary>
46+
public Func<IReadOnlyList<CsEvent>, bool> EventsSearch { get; init; } = null;
47+
48+
/// <summary>
49+
/// Stores the search criteria for constructors in the container.
50+
/// </summary>
51+
public Func<IReadOnlyList<CsMethod>, bool> ConstructorsSearch { get; init; } = null;
52+
53+
/// <summary>
54+
/// Stores the search criteria for searching the base class of the container.
55+
/// </summary>
56+
public Func<CsSearchContainer, bool> BaseSearch { get; init; } = null;
57+
58+
}
59+
}

Src/CodeFactoryForWindows/CodeFactory.WinVs/Models/ProjectSystem/IVsProjectActions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//* Copyright (c) 2020-2023 CodeFactory, LLC
44
//*****************************************************************************
55

6+
using CodeFactory.WinVs.Models.CSharp;
67
using System.Collections.Generic;
78
using System.Threading.Tasks;
89

@@ -68,5 +69,21 @@ public interface IVsProjectActions
6869
/// <returns>Readonly list of the referenced projects or an empty list if there is no referenced projects.</returns>
6970
Task<IReadOnlyList<VsProject>> GetReferencedProjects(VsProject source);
7071

72+
/// <summary>
73+
/// Asynchronously retrieves a collection of source code files from the specified Visual Studio project that
74+
/// match the given search criteria.
75+
/// </summary>
76+
/// <remarks>This method performs an asynchronous search within the provided project and applies
77+
/// the specified search criteria to identify matching source code files. Use the <paramref
78+
/// name="IgnoreFolderPaths"/> parameter to exclude specific folders from the search if needed.</remarks>
79+
/// <param name="source">The Visual Studio project to search for source code files.</param>
80+
/// <param name="searchCriteria">The criteria used to filter the source code files to be retrieved.</param>
81+
/// <param name="searchSubFolders">Flag that determines if sub folders from this location will be searched. Default value is <c>true</c>.</param>
82+
/// <param name="IgnoreFolderPaths">An optional collection of folder paths to exclude from the search. If <see langword="null"/>, no folders are
83+
/// excluded. When setting the folder paths just include the folder name. If you are going multiple folders deep use a forward slash as the folder seperator.</param>
84+
/// <returns>A task that represents the asynchronous operation. The task result contains a read-only list of <see
85+
/// cref="CsSource"/> objects that match the specified search criteria.</returns>
86+
Task<IReadOnlyList<CsSource>> FindCSharpSourceCodeAsync(VsProject source, CsSourceSearchCriteria searchCriteria, bool searchSubFolders = true, IEnumerable<string> IgnoreFolderPaths = null);
87+
7188
}
7289
}

Src/CodeFactoryForWindows/CodeFactory.WinVs/Models/ProjectSystem/IVsProjectFolderActions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//* Copyright (c) 2020-2023 CodeFactory, LLC
44
//*****************************************************************************
55

6+
using CodeFactory.WinVs.Models.CSharp;
67
using System.Collections.Generic;
78
using System.Threading.Tasks;
89

@@ -74,5 +75,21 @@ public interface IVsProjectFolderActions
7475
/// <param name="source">The project folder model to get the namespace for.</param>
7576
/// <returns>The fully qualified namespace if the project is a c# project that supports this project folder. Otherwise null will be returned.</returns>
7677
Task<string> GetCSharpNamespaceAsync(VsProjectFolder source);
78+
79+
/// <summary>
80+
/// Asynchronously retrieves a collection of source code files from the specified Visual Studio project folder that
81+
/// match the given search criteria.
82+
/// </summary>
83+
/// <remarks>This method performs an asynchronous search within the provided project and applies
84+
/// the specified search criteria to identify matching source code files. Use the <paramref
85+
/// name="IgnoreFolderPaths"/> parameter to exclude specific folders from the search if needed.</remarks>
86+
/// <param name="source">The Visual Studio project folder to search for source code files.</param>
87+
/// <param name="searchCriteria">The criteria used to filter the source code files to be retrieved.</param>
88+
/// <param name="searchSubFolders">Flag that determines if sub folders from this location will be searched. Default value is <c>true</c>.</param>
89+
/// <param name="IgnoreFolderPaths">An optional collection of folder paths to exclude from the search. If <see langword="null"/>, no folders are
90+
/// excluded. When setting the folder paths just include the folder name. If you are going multiple folders deep use a forward slash as the folder seperator.</param>
91+
/// <returns>A task that represents the asynchronous operation. The task result contains a read-only list of <see
92+
/// cref="CsSource"/> objects that match the specified search criteria.</returns>
93+
Task<IReadOnlyList<CsSource>> FindCSharpSourceCodeAsync(VsProjectFolder source, CsSourceSearchCriteria searchCriteria, bool searchSubFolders = true, IEnumerable<string> IgnoreFolderPaths = null);
7794
}
7895
}

Src/CodeFactoryForWindows/CodeFactory.WinVs/Models/ProjectSystem/VsProject.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//* Copyright (c) 2020-2023 CodeFactory, LLC
44
//*****************************************************************************
55

6+
using CodeFactory.WinVs.Models.CSharp;
67
using System.Collections.Generic;
78
using System.Collections.Immutable;
89
using System.Linq;
@@ -152,5 +153,20 @@ public async Task<IReadOnlyList<VsProject>> GetReferencedProjects()
152153

153154
return projects.Any() ? projects.ToImmutableList() : ImmutableList<VsProject>.Empty;
154155
}
156+
157+
/// <summary>
158+
/// Asynchronously retrieves a collection of source code files from the specified Visual Studio project that
159+
/// match the given search criteria.
160+
/// </summary>
161+
/// <remarks>This method performs an asynchronous search within the provided project and applies
162+
/// the specified search criteria to identify matching source code files. Use the <paramref
163+
/// name="IgnoreFolderPaths"/> parameter to exclude specific folders from the search if needed.</remarks>
164+
/// <param name="searchCriteria">The criteria used to filter the source code files to be retrieved.</param>
165+
/// <param name="searchSubFolders">Flag that determines if sub folders from this location will be searched. Default value is <c>true</c>.</param>
166+
/// <param name="IgnoreFolderPaths">An optional collection of folder paths to exclude from the search. If <see langword="null"/>, no folders are
167+
/// excluded. When setting the folder paths just include the folder name. If you are going multiple folders deep use a forward slash as the folder seperator.</param>
168+
/// <returns>A task that represents the asynchronous operation. The task result contains a read-only list of <see
169+
/// cref="CsSource"/> objects that match the specified search criteria.</returns>
170+
public abstract Task<IReadOnlyList<CsSource>> FindCSharpSourceCodeAsync(CsSourceSearchCriteria searchCriteria, bool searchSubFolders = true, IEnumerable<string> IgnoreFolderPaths = null);
155171
}
156172
}

Src/CodeFactoryForWindows/CodeFactory.WinVs/Models/ProjectSystem/VsProjectFolder.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//* Copyright (c) 2020-2023 CodeFactory, LLC
44
//*****************************************************************************
55

6+
using CodeFactory.WinVs.Models.CSharp;
67
using System.Collections.Generic;
78
using System.Threading.Tasks;
89

@@ -110,5 +111,20 @@ protected VsProjectFolder(bool isLoaded, bool hasErrors,
110111
/// </summary>
111112
/// <returns>The fully qualified namespace if the project is a c# project that supports this project folder. Otherwise null will be returned.</returns>
112113
public abstract Task<string> GetCSharpNamespaceAsync();
114+
115+
/// <summary>
116+
/// Asynchronously retrieves a collection of source code files from the specified Visual Studio project folder that
117+
/// match the given search criteria.
118+
/// </summary>
119+
/// <remarks>This method performs an asynchronous search within the provided project folder and applies
120+
/// the specified search criteria to identify matching source code files. Use the <paramref
121+
/// name="IgnoreFolderPaths"/> parameter to exclude specific folders from the search if needed.</remarks>
122+
/// <param name="searchCriteria">The criteria used to filter the source code files to be retrieved.</param>
123+
/// <param name="searchSubFolders">Flag that determines if sub folders from this location will be searched. Default value is <c>true</c>.</param>
124+
/// <param name="IgnoreFolderPaths">An optional collection of folder paths to exclude from the search. If <see langword="null"/>, no folders are
125+
/// excluded. When setting the folder paths just include the folder name. If you are going multiple folders deep use a forward slash as the folder seperator.</param>
126+
/// <returns>A task that represents the asynchronous operation. The task result contains a read-only list of <see
127+
/// cref="CsSource"/> objects that match the specified search criteria.</returns>
128+
public abstract Task<IReadOnlyList<CsSource>> FindCSharpSourceCodeAsync(CsSourceSearchCriteria searchCriteria, bool searchSubFolders = true, IEnumerable<string> IgnoreFolderPaths = null);
113129
}
114130
}

0 commit comments

Comments
 (0)