* The ` ` of the project files from `dir` up, and the * `global using X;` of each project's own files — a global using is its * project's alone: serilog's Serilog.Tests and Serilog.PerformanceTests each * `global using` their own `Support` namespace, and both define `Some`. *
(dir: string, context: ResolutionContext, memo: Map<string, { usings: Set<string>; project: boolean }>)
| 4243 | * `project` says whether a `.csproj` sits at `dir` or above it. |
| 4244 | */ |
| 4245 | function csharpProjectUsings(dir: string, context: ResolutionContext, memo: Map<string, { usings: Set<string>; project: boolean }>): { usings: Set<string>; project: boolean } { |
| 4246 | const key = dir; |
| 4247 | const hit = memo.get(key); |
| 4248 | if (hit) return hit; |
| 4249 | const root = dir === '.' || dir === '' || dir === '/'; |
| 4250 | const parent = root ? null : csharpProjectUsings(path.posix.dirname(dir), context, memo); |
| 4251 | const usings = new Set<string>(parent?.usings ?? []); |
| 4252 | let project = parent?.project ?? false; |
| 4253 | let entries: string[] = []; |
| 4254 | try { |
| 4255 | entries = fs.readdirSync(path.join(context.getProjectRoot(), root ? '' : dir)); |
| 4256 | } catch { |
| 4257 | entries = []; |
| 4258 | } |
| 4259 | for (const entry of entries) { |
| 4260 | if (!/\.(?:csproj|props)$/i.test(entry)) continue; |
| 4261 | let text = ''; |
| 4262 | try { |
| 4263 | text = fs.readFileSync(path.join(context.getProjectRoot(), root ? '' : dir, entry), 'utf8'); |
| 4264 | } catch { |
| 4265 | continue; |
| 4266 | } |
| 4267 | if (/\.csproj$/i.test(entry) && !project) { |
| 4268 | project = true; |
| 4269 | for (const u of csharpGlobalUsings(root ? '.' : dir, context)) usings.add(u); |
| 4270 | } |
| 4271 | for (const m of text.matchAll(/<Using\s+Include\s*=\s*"([\w.]+)"(?![^>]*\bStatic\s*=\s*"true")[^>]*>/gi)) usings.add(m[1]!); |
| 4272 | // The SDK's implicit usings (serilog's own `System.TimeProvider` polyfill is seen through them). |
| 4273 | if (/<ImplicitUsings>\s*(?:enable|true)\s*<\/ImplicitUsings>/i.test(text)) { |
| 4274 | for (const ns of CSHARP_IMPLICIT_USINGS) usings.add(ns); |
| 4275 | } |
| 4276 | } |
| 4277 | const result = { usings, project }; |
| 4278 | memo.set(key, result); |
| 4279 | return result; |
| 4280 | } |
| 4281 | |
| 4282 | const CSHARP_GLOBAL_USINGS = new WeakMap<ResolutionContext, Map<string, Set<string>>>(); |
| 4283 |
no test coverage detected