C# Syntax to CodeQL Mapping

C# Syntax Element C# Sample Code CodeQL Class
File N/A File
Source File N/A SourceFile
Directory N/A Folder
Class class MyClass { } Class
Struct struct MyStruct { int x; } Struct
Interface interface IMyInterface { void DoWork(); } Interface
C# Syntax Element C# Sample Code CodeQL Class
Files and Directories
File N/A File
Source File N/A SourceFile
Directory N/A Folder
Types
Class class MyClass { } Class
Struct struct MyStruct { int x; } Struct
Interface interface IMyInterface { void DoWork(); } Interface
Enum enum MyEnum { A, B, C } Enum
Delegate delegate void MyDelegate(string s); Delegate
Methods and Functions
Method void MyMethod() { } Method
Constructor MyClass() { } Constructor
Destructor ~MyClass() { } Destructor
Operator public static MyClass operator +(MyClass a) Operator
Local Function void LocalFunc() { } LocalFunction
Variables and Parameters
Variable int x = 10; Variable
Local Variable int localVar = 20; LocalVariable
Parameter void MyMethod(int param) { } Parameter
Field private int myField; Field
Statements
Block Statement { int x = 5; } BlockStmt
If Statement if (x > 0) { } IfStmt
For Statement for (int i = 0; i < 10; i++) { } ForStmt
Foreach Statement foreach (var item in items) { } ForEachStmt
While Statement while (x > 0) { } WhileStmt
Do-While Statement do { } while (x > 0); DoStmt
Switch Statement switch (x) { case 1: break; } SwitchStmt
Break Statement break; BreakStmt
Continue Statement continue; ContinueStmt
Return Statement return x; ReturnStmt
Throw Statement throw new Exception(); ThrowStmt
Try Statement try { } catch { } TryStmt
Catch Clause catch (Exception ex) { } CatchClause
Finally Clause finally { } FinallyClause
Using Statement using (var res = new Resource()) { } UsingStmt
Lock Statement lock (obj) { } LockStmt
Expressions
Expression x + y Expr
Literal Expression 42 Literal
Binary Operation x + y BinaryOperation
Unary Operation -x UnaryOperation
Assignment Expression x = 5 AssignExpr
Invocation Expression Console.WriteLine("Hello"); InvocationExpr
Object Creation Expression new MyClass() ObjectCreation
Array Creation Expression new int[10] ArrayCreation
Cast Expression (int)x CastExpr
Conditional Expression x > 0 ? y : z ConditionalExpr
Lambda Expression (x) => x * 2 LambdaExpr
Accessors and Properties
Property public int MyProp { get; set; } Property
Property Access x = MyProp; PropertyAccess
Indexer this[int index] Indexer
Indexer Access array[0] IndexerAccess
Events
Event public event EventHandler MyEvent; Event
Event Access MyEvent += handler; EventAccess
Attributes
Attribute [Obsolete("Message")] Attribute
Namespaces
Namespace namespace MyNamespace { } Namespace