MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / detect

Function detect

src/resolution/frameworks/csharp.ts:20–70  ·  view source on GitHub ↗
(context: ResolutionContext)

Source from the content-addressed store, hash-verified

18 resolveLanguages: ['csharp', 'razor'],
19
20 detect(context: ResolutionContext): boolean {
21 // Check for .csproj files with ASP.NET references
22 const allFiles = context.getAllFiles();
23 for (const file of allFiles) {
24 if (file.endsWith('.csproj')) {
25 const content = context.readFile(file);
26 if (content && (
27 content.includes('Microsoft.AspNetCore') ||
28 content.includes('Microsoft.NET.Sdk.Web') ||
29 content.includes('System.Web.Mvc')
30 )) {
31 return true;
32 }
33 }
34 }
35
36 // Check for Program.cs with WebApplication
37 const programCs = context.readFile('Program.cs');
38 if (programCs && (
39 programCs.includes('WebApplication') ||
40 programCs.includes('CreateHostBuilder') ||
41 programCs.includes('UseStartup')
42 )) {
43 return true;
44 }
45
46 // Check for Startup.cs (ASP.NET Core signature)
47 if (context.fileExists('Startup.cs')) {
48 return true;
49 }
50
51 // ASP.NET signatures in controller/entrypoint SOURCE — covers feature-folder
52 // apps with no `/Controllers/` dir and a subdir `Program.cs` that the
53 // root-only checks above miss (e.g. realworld: Features/*/FooController.cs).
54 // `.csproj` often isn't in the indexed source set, so source-scan is the
55 // reliable signal.
56 // Endpoint-group apps (`Endpoints/TodoItems.cs : IEndpointGroup`) have
57 // none of those names: their files, and the extension that maps them, count.
58 for (const file of allFiles) {
59 if (!/(?:Controller|Program|Startup|Endpoints?|Extensions)\.cs$/.test(file) && !/(?:^|\/)Endpoints\/[^/]+\.cs$/.test(file)) continue;
60 const c = context.readFile(file);
61 if (c && (
62 /\[(?:ApiController|Route|Http(?:Get|Post|Put|Patch|Delete))\b/.test(c) ||
63 c.includes('ControllerBase') || c.includes(': Controller') ||
64 c.includes('MapControllers') || c.includes('WebApplication') ||
65 c.includes('Microsoft.AspNetCore') || c.includes('IEndpointGroup') ||
66 c.includes('EndpointGroupBase') || c.includes('RouteGroupBuilder')
67 )) return true;
68 }
69 return false;
70 },
71
72 resolve(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null {
73 // Pattern 1: Controller references

Callers

nothing calls this directly

Calls 3

readFileMethod · 0.80
fileExistsMethod · 0.80
getAllFilesMethod · 0.65

Tested by

no test coverage detected