* The parameter list of a C# method, read from its declaration: past its * attribute sections (`[Obsolete("Put(int) instead")]`), the `( … )` after * its name — and type parameters, `Save (…)` — with comments and string * literals blanked. An explicit interface implementation, `object * IStore
(method: Node, context: ResolutionContext)
| 194 | * IStore.Put(string key)`, is named `Put` like any other. |
| 195 | */ |
| 196 | function csharpParameterList(method: Node, context: ResolutionContext): string | null { |
| 197 | const lines = context.getFileLines?.(method.filePath) ?? context.readFile(method.filePath)?.split(/\r?\n/) ?? null; |
| 198 | if (!lines || method.startLine < 1 || method.startLine > lines.length) return null; |
| 199 | const end = Math.min(lines.length, Math.max(method.endLine, method.startLine), method.startLine - 1 + CSHARP_HEAD_LINES); |
| 200 | const first = lines[method.startLine - 1]!; |
| 201 | const head = blankCsharpTrivia( |
| 202 | [first.slice(Math.min(method.startColumn, first.length)), ...lines.slice(method.startLine, end)].join('\n') |
| 203 | ); |
| 204 | let at = 0; |
| 205 | for (;;) { |
| 206 | while (at < head.length && /\s/.test(head[at]!)) at++; |
| 207 | if (head[at] !== '[') break; |
| 208 | const close = closingBracket(head, at); |
| 209 | if (close < 0) return null; |
| 210 | at = close + 1; |
| 211 | } |
| 212 | const name = new RegExp(`(?<![\\w@])@?${escapeRegExp(method.name)}\\s*(?:<[^<>()]*>)?\\s*\\(`, 'g'); |
| 213 | name.lastIndex = at; |
| 214 | const found = name.exec(head); |
| 215 | if (!found) return null; |
| 216 | const open = found.index + found[0].length - 1; |
| 217 | const close = closingBracket(head, open); |
| 218 | return close < 0 ? null : head.slice(open + 1, close); |
| 219 | } |
| 220 | |
| 221 | /** C# source with its comments and the contents of its string and character literals blanked, newlines kept. */ |
| 222 | function blankCsharpTrivia(text: string): string { |
no test coverage detected