Skip to content

C#

Last verified end to end: 2026-07-14 (query_code schema version 2).

For exact inbound and outbound symbol edges, proof tiers, and adapter-specific caveats, see Reference Traversal.

C# exposes object creation, null-conditional access, named arguments, attributes, constructors, properties, and using aliases through normalized structural facts. Alias bindings are represented by their visible alias, not by the terminal name of the target type.

using System;
using App.Support;
using WriterAlias = App.Support.Writer;
namespace App;
[Route("/run")]
class Service {
private string empty;
public Service() {}
public string Run(string code) {
AuditNamed(code: code);
return code;
}
public static string AuditNamed(string code) => code;
}
class AppEntry {
void Main() {
var service = new Service();
service?.Run("optional");
}
}

The receiver and argument predicates select the null-conditional call. Named arguments use kwargs, with the identifier capture proving which value was bound to code.

(language csharp
(call :callee (name "Run") :receiver (name "service")
:args [(string_literal (text/regex "^\\\"optional\\\"$"))]))
{"languages":["csharp"],"match":{"kind":"call","callee":{"name":"Run"},"receiver":{"name":"service"},"args":[{"kind":"string_literal","text":{"regex":"^\\\"optional\\\"$"}}]}}
{
"results": [
{
"enclosing_symbol": "App.AppEntry.Main",
"end_line": 23,
"kind": "call",
"language": "csharp",
"result_type": "structural_match",
"path": "csharp/App.cs",
"start_line": 23,
"text": "service?.Run(\"optional\")"
}
],
"truncated": false
}
(language csharp
(call :callee (name "AuditNamed")
:kwargs [(code (identifier :name "code" :capture "value"))]))
{"languages":["csharp"],"match":{"kind":"call","callee":{"name":"AuditNamed"},"kwargs":{"code":{"kind":"identifier","name":"code","capture":"value"}}}}
{
"results": [
{
"captures": [
{"name": "value", "start_line": 13, "text": "code"}
],
"enclosing_symbol": "App.Service.Run",
"end_line": 13,
"kind": "call",
"language": "csharp",
"result_type": "structural_match",
"path": "csharp/App.cs",
"start_line": 13,
"text": "AuditNamed(code: code)"
}
],
"truncated": false
}

Attributes are decorators on the class. An alias import matches WriterAlias, but querying the target terminal name Writer must remain empty so an alias does not overmatch.

(language csharp (class :decorators [(name "Route")]))
{"languages":["csharp"],"match":{"kind":"class","decorators":[{"name":"Route"}]}}
{
"results": [
{
"enclosing_symbol": "App.Service",
"end_line": 18,
"kind": "class",
"language": "csharp",
"result_type": "structural_match",
"path": "csharp/App.cs",
"start_line": 7,
"text": "[Route(\"/run\")]…"
}
],
"truncated": false
}
(language csharp (import :module (name "WriterAlias")))
{"languages":["csharp"],"match":{"kind":"import","module":{"name":"WriterAlias"}}}
{
"results": [
{
"end_line": 3,
"kind": "import",
"language": "csharp",
"result_type": "structural_match",
"path": "csharp/App.cs",
"start_line": 3,
"text": "using WriterAlias = App.Support.Writer;"
}
],
"truncated": false
}
(language csharp (import :module (name "Writer")))
{"languages":["csharp"],"match":{"kind":"import","module":{"name":"Writer"}}}
{
"results": [],
"truncated": false
}

Uninitialized declarations such as empty are intentionally not assignments. Querying assignment with that left name is a useful exact-zero check when auditing initialization patterns.

class QueryRoot {
public void RootMember() {}
}
class QueryLeaf : QueryRoot {
public void LeafMember() {}
}
(supertypes :depth 2 (enclosing-decl (language csharp (class :name "QueryLeaf"))))
{"languages":["csharp"],"match":{"kind":"class","name":"QueryLeaf"},"steps":[{"op":"enclosing_decl"},{"op":"supertypes","depth":2}]}
{
"results": [
{
"end_line": 3,
"fq_name": "QueryRoot",
"kind": "class",
"language": "csharp",
"path": "csharp/QueryHierarchy.cs",
"provenance": [
{
"seed": {
"end_line": 7,
"kind": "class",
"path": "csharp/QueryHierarchy.cs",
"result_type": "structural_match",
"start_line": 5
},
"steps": [
{
"op": "enclosing_decl",
"result": {
"end_line": 7,
"fq_name": "QueryLeaf",
"kind": "class",
"path": "csharp/QueryHierarchy.cs",
"result_type": "declaration",
"start_line": 5
}
},
{
"op": "supertypes",
"result": {
"end_line": 3,
"fq_name": "QueryRoot",
"kind": "class",
"path": "csharp/QueryHierarchy.cs",
"result_type": "declaration",
"start_line": 1
}
}
]
}
],
"result_type": "declaration",
"signature": "class QueryRoot {",
"start_line": 1
}
],
"truncated": false
}
(owner (members (subtypes :transitive true (enclosing-decl (language csharp (class :name "QueryRoot"))))))
{"languages":["csharp"],"match":{"kind":"class","name":"QueryRoot"},"steps":[{"op":"enclosing_decl"},{"op":"subtypes","transitive":true},{"op":"members"},{"op":"owner"}]}
{
"results": [
{
"end_line": 7,
"fq_name": "QueryLeaf",
"kind": "class",
"language": "csharp",
"path": "csharp/QueryHierarchy.cs",
"provenance": [
{
"seed": {
"end_line": 3,
"kind": "class",
"path": "csharp/QueryHierarchy.cs",
"result_type": "structural_match",
"start_line": 1
},
"steps": [
{
"op": "enclosing_decl",
"result": {
"end_line": 3,
"fq_name": "QueryRoot",
"kind": "class",
"path": "csharp/QueryHierarchy.cs",
"result_type": "declaration",
"start_line": 1
}
},
{
"op": "subtypes",
"result": {
"end_line": 7,
"fq_name": "QueryLeaf",
"kind": "class",
"path": "csharp/QueryHierarchy.cs",
"result_type": "declaration",
"start_line": 5
}
},
{
"op": "members",
"result": {
"end_line": 6,
"fq_name": "QueryLeaf.LeafMember",
"kind": "function",
"path": "csharp/QueryHierarchy.cs",
"result_type": "declaration",
"start_line": 6
}
},
{
"op": "owner",
"result": {
"end_line": 7,
"fq_name": "QueryLeaf",
"kind": "class",
"path": "csharp/QueryHierarchy.cs",
"result_type": "declaration",
"start_line": 5
}
}
]
}
],
"result_type": "declaration",
"signature": "class QueryLeaf : QueryRoot {",
"start_line": 5
}
],
"truncated": false
}