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

Function detect

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

fileExistsMethod · 0.80
getAllFilesMethod · 0.65
readFileMethod · 0.65

Tested by

no test coverage detected