Skip to content

Commit 8af0ba7

Browse files
committed
Add nestedName function for C#
Similar to #2553, this changes the C# query to correctly report the name of nested types. I couldn't find a `nestedName` method for C#, so this adds one in the `AutomodelVsCode` library. C# seems to use `+` as a separator for nested types, as reported by `getQualifiedName()`: ``` GitHub.Nested.MyFirstClass+NestedClass ``` The `getApiName()` will now report: ``` GitHub.Nested#MyFirstClass+NestedClass.Test() ```
1 parent 3ad3644 commit 8af0ba7

File tree

1 file changed

+16
-1
lines changed
  • extensions/ql-vscode/src/data-extensions-editor/queries

1 file changed

+16
-1
lines changed

extensions/ql-vscode/src/data-extensions-editor/queries/csharp.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class CallableMethod extends DotNet::Declaration {
104104
bindingset[this]
105105
private string getSignature() {
106106
result =
107-
this.getDeclaringType().getUnboundDeclaration() + "." + this.getName() + "(" +
107+
nestedName(this.getDeclaringType().getUnboundDeclaration()) + "." + this.getName() + "(" +
108108
parameterQualifiedTypeNamesToString(this) + ")"
109109
}
110110
@@ -178,6 +178,21 @@ boolean isSupported(CallableMethod callableMethod) {
178178
not callableMethod.isSupported() and
179179
result = false
180180
}
181+
182+
/**
183+
* Gets the nested name of the declaration.
184+
*
185+
* If the declaration is not a nested type, the result is the same as \`getName()\`.
186+
* Otherwise the name of the nested type is prefixed with a \`+\` and appended to
187+
* the name of the enclosing type, which might be a nested type as well.
188+
*/
189+
private string nestedName(Declaration declaration) {
190+
not exists(declaration.getDeclaringType().getUnboundDeclaration()) and
191+
result = declaration.getName()
192+
or
193+
nestedName(declaration.getDeclaringType().getUnboundDeclaration()) + "+" + declaration.getName() =
194+
result
195+
}
181196
`,
182197
},
183198
};

0 commit comments

Comments
 (0)