Docs / languages / csharp · Edit on GitHub

C#

Tier 1 plugin for C# source. Extracts namespaces, classes, attributes, new expressions, and method call binding with namespace-qualified names.

Implementation

Plugin cratecrates/rgctl-lang-csharp (CSharpPlugin)
Grammartree-sitter-c-sharp
Extensions.cs
Discoverrgctl discover . -l csharp -e bin,obj,data --with-cfg
CFG / taintEnabled

Tree-sitter node kinds: method_declaration, local_function_statement, constructor_declaration, class_declaration, struct_declaration, interface_declaration, using_directive.

What is extracted

Nodes

  • Function — methods, local functions, constructors
  • Class, Struct, Interface, Enum
  • Importusing directives

Edges

EdgeMeaning
CALLSMethod and constructor calls
ANNOTATEDWITHAttributes ([Authorize], …)
INSTANTIATESnew expressions
EXTENDS / IMPLEMENTSInheritance and interface implementation

qualified_name uses namespace prefix (e.g. Ecommerce.Services.OrderService.CheckoutAsync).

Verification

Fixturergctl-tests/ecommerce-csharp
Example corpusexample/roslyn/src (-l csharp)
Smoke scriptrgctl-tests/gql-verification-smoke/verify-extraction-gql-csharp.sh

GQL verification queries

Fixture probes

ProbeGQL
Attributes (ANNOTATEDWITH)MATCH (a)-[:ANNOTATEDWITH]->(b) RETURN a,b LIMIT 10000
Instantiation (INSTANTIATES)MATCH (a)-[:INSTANTIATES]->(b) RETURN a,b LIMIT 10000
Call binding (CALLS)MATCH (a)-[:CALLS]->(b) RETURN a,b LIMIT 10000
Namespace FQNMATCH (n:Function) WHERE n.qualified_name LIKE 'Ecommerce.*' RETURN n LIMIT 20

Example smoke (example/roslyn/src)

ProbeGQL
ANNOTATEDWITH (scale)MATCH (a)-[:ANNOTATEDWITH]->(b) RETURN a,b LIMIT 10000
INSTANTIATES (scale)MATCH (a)-[:INSTANTIATES]->(b) RETURN a,b LIMIT 10000
CALLS (scale)MATCH (a)-[:CALLS]->(b) RETURN a,b LIMIT 10000

Related

  • Languages index
  • Openspec: csharp-annotations, csharp-instantiation, csharp-call-binding, csharp-namespace-fqn