C# srcML Language Documentation

Statements XML Element Subelements

if statement

<if>

<condition>, <then>, <else>, <elseif>

while statement

<while>

<condition>, <block>

for statement

<for>

<control>, <block>

foreach .. in statement

<foreach>

<control>, <block>

do statement

<do>

<block>, <condition>

break statement

<break>

continue statement

<continue>

return statement

<return>

<expr>

switch statement

<switch>

<condition>, <case>, <block>

case statement

<case>

<expr>

default statement

<default>

block

<block>

label

<label>

<name>

goto statement

<goto>

<name>

empty statement

<empty_stmt>

fixed statement

<fixed>

<parameter_list>, <block>

lock statement

<lock>

<init>, <block>

using statement

<using>

<init>, <block>

unsafe statement

<unsafe>

<block>

Specifiers XML Element Subelements

const

<specifier>

readonly

<specifier>

public

<specifier>

private

<specifier>

protected

<specifier>

internal

<specifier>

protected internal

<specifier>

static

<specifier>

volatile

<specifier>

out (output parameter)

<modifier>

ref

<modifier>

params

<specifier>

extern specifier

<specifier>

virtual

<specifier>

override

<specifier>

new

<specifier>

sealed

<specifier>

async

<specifier>

partial

<specifier>

explicit

<specifier>

implicit

<specifier>

yield

<specifier>

this (extension methods)

<specifier>

Declarations, Definitions and Initializations XML Element Subelements

variable declaration statement

<decl_stmt>

<decl>

variable declaration

<decl>

<name>, <init>

nullable variable modifier

<decl>

<name>, <init>

array declaration

<decl>

<name>, <index>

function declaration

<function_decl>

<type>, <name>, <parameter_list>

function definition

<function>

<type>, <name>, <parameter_list>

default arguments

<init>

<expr>

delegate type definition

<function_decl>

<type>, <name>, <parameter_list>

anonymous methods

<lambda>

<parameter_list>, <block>

lambda

<lambda>

<parameter_list>, <name_list>, <operator>, <block>

namespace

<namespace>

<name>, <block>

using directive

<using>

<name>, <init>

extern alias

<extern>

operator overloading

<function>

<type>, <name>, <parameter_list>

indexer property

<function_decl>

<type>, <name>, <parameter_list>

implicit conversion operator definition

<function>

<name>, <parameter_list>

explicit conversion operator definition

<function>

<type>, <name>, <parameter_list>

operator false

<function>

<type>, <name>, <parameter_list>

operator true

<function>

<type>, <name>, <parameter_list>

pointer declaration

<modifier>

Classes, Structs, Interfaces and Enums XML Element Subelements

class

<class>

<suepr>, <name>, <block>

struct

<struct>

<name>, <super>

interface

<interface>

<name>, <super>, <block>

anonymous type

<expr>

<name>

property

<decl_stmt>

<type>, <name>, <block>

get

<function>

<name>, <block>

get (default implementation)

<function_decl>

<name>

set

<function>

<name>, <block>

set (default implementation)

<function_decl>

<name>

event

<decl_stmt>

<type>, <name>, <block>

add

<function>

<name>, <block>

remove

<function>

<name>, <block>

inheritance list

<super>

<specifier>, <name>

constructor

<constructor>

<name>, <parameter_list>, <block>

this (constructor forwarding)

<name>

base (constructor selection)

<name>

destructor

<destructor>

<name>

object initializer

<decl_stmt>

<decl>, <init>, <block>

enum

<enum>

<name>, <block>

disambiguating function override

<function>

<type>, <name>, <parameter_list>, <block>

Expressions XML Element Subelements

function call

<call>

<name>, <argument_list>

named parameters

<call>

<name>, <argument_list>

new

<operator>

stackalloc

<operator>

array indexing

<name>

<name>, <index>

ternary operator

<ternary>

<condition>, <then>, <else>

dereference member access

<expr>

<name>, <operator>

member and scope access

<expr>

<name>, <operator>

this (object)

<name>

base (object)

<name>

Other XML Element Subelements

typeof

<typeof>

<argument_list>

default (object construction)

<default>

<argument_list>

checked

<checked>

<block>

unchecked

<unchecked>

<block>

sizeof

<sizeof>

<argument_list>

var

<name>

object

<name>

dynamic

<name>

string keyword

<name>

cast

<operator>

<name>

attribute

<attribute>

<expr>

global

<name>

<name>, <operator>

Generics XML Element Subelements

generic variable declaration

<decl>

<src:name>

generic class

<class>

<specifier>, <name>, <block>

generic method

<function>

<type>, <name>, <parameter_list>, <block>

in (generic parameter constraint)

<specifier>

out (generic parameter constraint)

<specifier>

where (constraint)

<where>

<name>

new (constraint)

<name>

class (constraint)

<constraint>

struct (constraint)

<constraint>

Exceptions XML Element Subelements

throw

<throw>

<expr>

try

<try>

<block>, <catch>

catch

<catch>

<parameter_list>

finally

<finally>

<block>

LINQ XML Element Subelements

from

<from>

<expr>, <in>

where (clause)

<where>

<expr>

select

<select>

<expr>

group

<group>

<by>, <into>

orderby

<orderby>

<expr>, <name>

join

<join>

<in>, <on>, <equals>, <into>

let

<let>

<expr>

C# Preprocessor XML Element Subelements

#if

<cpp:if>

<cpp:directive>, <expr>

#else

<cpp:else>

<cpp:directive>

#elif

<cpp:elif>

<cpp:directive>, <expr>

#endif

<cpp:endif>

<cpp:directive>

#define

<cpp:define>

<cpp:directive>, <expr>

#undef

<cpp:undef>

<cpp:directive>, <cpp:macro>

#warning

<cpp:warning>

<cpp:directive>

#error

<cpp:error>

<cpp:directive>

#line

<cpp:line>

<cpp:directive>, <cpp:number>, <cpp:file>

#region

<cpp:region>

<cpp:directive>, <name>

#endregion

<cpp:endregion>

<cpp:directive>

#pragma

<cpp:pragma>

<cpp:directive>, <name>

if statement


Element

Subelements

XPath Queries

  • if statements

    //src:if
  • if-statement conditions

    //src:if/src:condition
  • then statements

    //src:if/src:then
  • else statements, but not else-if statements

    //src:if/src:else
  • if statements without an else statement, this doesn’t include else if sections of an if statement

    //src:if[count(src:else) = 0]
  • nested if statements

    //src:if//src:if
  • else-if statements

    //src:elseif

Examples

if(x > 5)
    y+=4;
<if>if<condition>(<expr><name>x</name> <operator>&gt;</operator> <literal type="number">5</literal></expr>)</condition><then><block type="pseudo">
    <expr_stmt><expr><name>y</name><operator>+=</operator><literal type="number">4</literal></expr>;</expr_stmt></block></then></if>
if ( i > 0 ) {
    y = x / i;
}
<if>if <condition>( <expr><name>i</name> <operator>&gt;</operator> <literal type="number">0</literal></expr> )</condition><then> <block>{
    <expr_stmt><expr><name>y</name> <operator>=</operator> <name>x</name> <operator>/</operator> <name>i</name></expr>;</expr_stmt>
}</block></then></if>
if ( i > 0 )
    y = x / i;
else 
{
    x = i;
    y = f( x );
}
<if>if <condition>( <expr><name>i</name> <operator>&gt;</operator> <literal type="number">0</literal></expr> )</condition><then><block type="pseudo">
    <expr_stmt><expr><name>y</name> <operator>=</operator> <name>x</name> <operator>/</operator> <name>i</name></expr>;</expr_stmt></block></then>
<else>else 
<block>{
    <expr_stmt><expr><name>x</name> <operator>=</operator> <name>i</name></expr>;</expr_stmt>
    <expr_stmt><expr><name>y</name> <operator>=</operator> <call><name>f</name><argument_list>( <argument><expr><name>x</name></expr></argument> )</argument_list></call></expr>;</expr_stmt>
}</block></else></if>

Without braces

if ( i > 0 )
    if ( j > i )
        x = j;
    else
        x = i;
<if>if <condition>( <expr><name>i</name> <operator>&gt;</operator> <literal type="number">0</literal></expr> )</condition><then><block type="pseudo">
    <if>if <condition>( <expr><name>j</name> <operator>&gt;</operator> <name>i</name></expr> )</condition><then><block type="pseudo">
        <expr_stmt><expr><name>x</name> <operator>=</operator> <name>j</name></expr>;</expr_stmt></block></then>
    <else>else<block type="pseudo">
        <expr_stmt><expr><name>x</name> <operator>=</operator> <name>i</name></expr>;</expr_stmt></block></else></if></block></then></if>

With braces

if ( i > 0 ) 
{
    if ( j > i )
        x = j;
}
else
    x = i;
<if>if <condition>( <expr><name>i</name> <operator>&gt;</operator> <literal type="number">0</literal></expr> )</condition><then> 
<block>{
    <if>if <condition>( <expr><name>j</name> <operator>&gt;</operator> <name>i</name></expr> )</condition><then><block type="pseudo">
        <expr_stmt><expr><name>x</name> <operator>=</operator> <name>j</name></expr>;</expr_stmt></block></then></if>
}</block></then>
<else>else<block type="pseudo">
    <expr_stmt><expr><name>x</name> <operator>=</operator> <name>i</name></expr>;</expr_stmt></block></else></if>
if ( i > 0 ) 
{
 	x = i;   
}
else if( i < 0)
	x = q;
else 
    x = j;
<if>if <condition>( <expr><name>i</name> <operator>&gt;</operator> <literal type="number">0</literal></expr> )</condition><then> 
<block>{
 	<expr_stmt><expr><name>x</name> <operator>=</operator> <name>i</name></expr>;</expr_stmt>   
}</block></then>
<elseif>else <if>if<condition>( <expr><name>i</name> <operator>&lt;</operator> <literal type="number">0</literal></expr>)</condition><then><block type="pseudo">
	<expr_stmt><expr><name>x</name> <operator>=</operator> <name>q</name></expr>;</expr_stmt></block></then></if></elseif>
<else>else<block type="pseudo"> 
    <expr_stmt><expr><name>x</name> <operator>=</operator> <name>j</name></expr>;</expr_stmt></block></else></if>

while statement


Element

Subelements

XPath Queries

  • while loops

    //src:while
  • while-loop conditions

    //src:while/src:condition
  • while loops with a condition containing the variable i

    //src:while[src:condition//src:name = 'i']

Example

while ( i >= 0 ) 
{
    string1[i] = string2[i];
    i--;
}
<while>while <condition>( <expr><name>i</name> <operator>&gt;=</operator> <literal type="number">0</literal></expr> )</condition> 
<block>{
    <expr_stmt><expr><name><name>string1</name><index>[<expr><name>i</name></expr>]</index></name> <operator>=</operator> <name><name>string2</name><index>[<expr><name>i</name></expr>]</index></name></expr>;</expr_stmt>
    <expr_stmt><expr><name>i</name><operator>--</operator></expr>;</expr_stmt>
}</block></while>

for statement


Element

Subelements

XPath Queries

  • for loops

    //src:for
  • for-loop initialization statements

    //src:for/src:control/src:init
  • for-loop conditions

    //src:for/src:control/src:condition
  • for-loop increment expressions

    //src:for/src:control/src:incr
  • for loops which declare a variable with a single character name (e.g. x, i or y)

    //src:for[string-length(src:control/src:init/src:decl/src:name) = 1]
  • for loops which use post increment as part of the increment expression

    //src:for[src:control/src:incr/src:expr//node()/following-sibling::src:operator[.= '++']]

Examples

for( ;; ) { }
<for>for<control>( <init>;</init><condition>;</condition> <incr/>)</control> <block>{ }</block></for>
for (i = 0; i < max; i++ ) 
{
  if ( line[i] == ' ' )
  {
      space++;
  }
  if ( line[i] == '\t' )
  {
      tab++;
  }
}
<for>for <control>(<init><expr><name>i</name> <operator>=</operator> <literal type="number">0</literal></expr>;</init> <condition><expr><name>i</name> <operator>&lt;</operator> <name>max</name></expr>;</condition> <incr><expr><name>i</name><operator>++</operator></expr></incr> )</control> 
<block>{
  <if>if <condition>( <expr><name><name>line</name><index>[<expr><name>i</name></expr>]</index></name> <operator>==</operator> <literal type="char">' '</literal></expr> )</condition><then>
  <block>{
      <expr_stmt><expr><name>space</name><operator>++</operator></expr>;</expr_stmt>
  }</block></then></if>
  <if>if <condition>( <expr><name><name>line</name><index>[<expr><name>i</name></expr>]</index></name> <operator>==</operator> <literal type="char">'\t'</literal></expr> )</condition><then>
  <block>{
      <expr_stmt><expr><name>tab</name><operator>++</operator></expr>;</expr_stmt>
  }</block></then></if>
}</block></for>
for(int i =0; i < 10;++i)
	a += x[i];
<for>for<control>(<init><decl><type><name>int</name></type> <name>i</name> <init>=<expr><literal type="number">0</literal></expr></init></decl>;</init> <condition><expr><name>i</name> <operator>&lt;</operator> <literal type="number">10</literal></expr>;</condition><incr><expr><operator>++</operator><name>i</name></expr></incr>)</control><block type="pseudo">
	<expr_stmt><expr><name>a</name> <operator>+=</operator> <name><name>x</name><index>[<expr><name>i</name></expr>]</index></name></expr>;</expr_stmt></block></for>

return statement


Element

Subelement

XPath Queries

  • return statements

    //src:return
  • functions with more then one return

    //src:function[ count(.//src:return) > 1]

Examples

return( s * (long long)s );
<return>return<expr><operator>(</operator> <name>s</name> <operator>*</operator> <operator>(</operator><name>long</name> <name>long</name><operator>)</operator><name>s</name> <operator>)</operator></expr>;</return>
return;
<return>return;</return>

case statement


Element

Subelement

XPath Queries

  • case labels

    //src:case
  • case labels which use SATURDAY

    //src:case[.//src:name = 'SATURDAY']
  • switch statements that have a case that uses SATURDAY

    //src:switch[src:block/src:case[.//src:name = 'SATURDAY']]

Example

case THREE:
<case>case <expr><name>THREE</name></expr>:</case>

default statement


Element

XPath Queries

  • default labels

    //src:default
  • switch statements with a default label

    //src:switch[src:block/src:default]

Example

default:
<default>default:</default>

label


Element

Subelement

XPath Queries

  • labels

    //src:label
  • labels without a corresponding goto statement

    //src:label[not(src:name[. = //src:goto/src:name])]

Example

stop:
<label><name>stop</name>:</label>

goto statement


Element

Subelement

XPath Queries

  • goto statements

    //src:goto
  • goto-statement case labels

    BUG
  • goto-statement default case labels

    BUG

Examples

goto stop;
<goto>goto <name>stop</name>;</goto>
goto case 1;
<goto>goto <name>case <literal type="number">1</literal></name>;</goto>
goto default;
<goto>goto default;</goto>

empty statement


Element

XPath Query

  • empty statements

    //src:empty_stmt

Example

;
<empty_stmt>;</empty_stmt>

lock statement


Element

Subelements

XPath Query

  • lock statements

    //src:lock

Example

lock (thisLock) {
}
<lock>lock <init>(<expr><name>thisLock</name></expr>)</init> <block>{
}</block></lock>

unsafe statement


Element

Subelement

XPath Query

  • unsafe statements

    //src:unsafe

Example

unsafe
{
}
<unsafe>unsafe
<block>{
}</block></unsafe>

const


Element

XPath Query

  • const variables

    //src:decl[src:type/src:specifier [.='const']]

Example

const int i = 6;
<decl_stmt><decl><type><specifier>const</specifier> <name>int</name></type> <name>i</name> <init>= <expr><literal type="number">6</literal></expr></init></decl>;</decl_stmt>

readonly


Element

XPath Query

  • readonly variables

    //src:decl[src:type/src:specifier [.='readonly']]

Example

readonly int i = 4;
<decl_stmt><decl><type><specifier>readonly</specifier> <name>int</name></type> <name>i</name> <init>= <expr><literal type="number">4</literal></expr></init></decl>;</decl_stmt>

public


Element

XPath Queries

  • public classes

    //src:class[src:specifier[.='public']]
  • public methods

    //src:function[src:type/src:specifier[.='public']]
  • public properties

    //src:property[src:type/src:specifier[.='public']]

Examples

public int field = 1;
<decl_stmt><decl><specifier>public</specifier> <type><name>int</name></type> <name>field</name> <init>= <expr><literal type="number">1</literal></expr></init></decl>;</decl_stmt>
public class Foo
{ 
}
<class><specifier>public</specifier> class <name>Foo</name>
<block>{ 
}</block></class>
public void doWork()
{
}
<function><specifier>public</specifier> <type><name>void</name></type> <name>doWork</name><parameter_list>()</parameter_list>
<block>{
}</block></function>
public string Name {
    get;
    set;
}
<property><specifier>public</specifier> <type><name>string</name></type> <name>Name</name> <block>{
    <function_decl><name>get</name>;</function_decl>
    <function_decl><name>set</name>;</function_decl>
}</block></property>

private


Element

XPath Queries

  • explicitly private classes

    //src:class[src:specifier[.='private']]
  • explicitly private methods

    //src:function[src:type/src:specifier[.='private']]
  • explicitly private properties

    //src:property[src:type/src:specifier[.='private']]

Examples

private int field = 1;
<decl_stmt><decl><specifier>private</specifier> <type><name>int</name></type> <name>field</name> <init>= <expr><literal type="number">1</literal></expr></init></decl>;</decl_stmt>
private class Foo
{ 
}
<class><specifier>private</specifier> class <name>Foo</name>
<block>{ 
}</block></class>
private void doWork()
{
}
<function><specifier>private</specifier> <type><name>void</name></type> <name>doWork</name><parameter_list>()</parameter_list>
<block>{
}</block></function>
private string Name {
    get;
    set;
}
<property><specifier>private</specifier> <type><name>string</name></type> <name>Name</name> <block>{
    <function_decl><name>get</name>;</function_decl>
    <function_decl><name>set</name>;</function_decl>
}</block></property>

protected


Element

XPath Queries

  • protected methods

    //src:function[src:type/src:specifier[.='protected']]
  • protected properties

    //src:property[src:type/src:specifier[.='protected']]

Examples

protected int field = 1;
<decl_stmt><decl><specifier>protected</specifier> <type><name>int</name></type> <name>field</name> <init>= <expr><literal type="number">1</literal></expr></init></decl>;</decl_stmt>
protected class Foo
{ 
}
<class><specifier>protected</specifier> class <name>Foo</name>
<block>{ 
}</block></class>
protected void doWork()
{
}
<function><specifier>protected</specifier> <type><name>void</name></type> <name>doWork</name><parameter_list>()</parameter_list>
<block>{
}</block></function>
protected string Name {
    get;
    set;
}
<property><specifier>protected</specifier> <type><name>string</name></type> <name>Name</name> <block>{
    <function_decl><name>get</name>;</function_decl>
    <function_decl><name>set</name>;</function_decl>
}</block></property>

protected internal


Element

XPath Query

  • protected internal fields

    //src:decl_stmt[src:decl[not(src:block)]/src:type[src:specifier[.='protected']][src:specifier[.='internal']]]

Example

protected internal int field = 1;
<decl_stmt><decl><specifier>protected</specifier> <specifier>internal</specifier> <type><name>int</name></type> <name>field</name> <init>= <expr><literal type="number">1</literal></expr></init></decl>;</decl_stmt>

static


Element

XPath Queries

  • static classes

    //src:class[src:specifier ='static']
  • static function

    //src:function[src:type/src:specifier ='static']
  • static fields

    //src:decl_stmt[src:decl/src:type/src:specifier ='static']
  • static events

    //src:event[src:type/src:specifier = 'static']
  • static properties

    //src:property[src:type/src:specifier = 'static']
  • static constructors

    //src:constructor[src:specifier ='static']

Examples

static class Foo {
}
<class><specifier>static</specifier> class <name>Foo</name> <block>{
}</block></class>
static void initialize() {
}
<function><specifier>static</specifier> <type><name>void</name></type> <name>initialize</name><parameter_list>()</parameter_list> <block>{
}</block></function>
static int counter = 5;
<decl_stmt><decl><specifier>static</specifier> <type><name>int</name></type> <name>counter</name> <init>= <expr><literal type="number">5</literal></expr></init></decl>;</decl_stmt>
class Foo {
    static event ReadHandler OnRead;
}
<class>class <name>Foo</name> <block>{
    <event><specifier>static</specifier> event <type><name>ReadHandler</name></type> <name>OnRead</name>;</event>
}</block></class>
static string Name {
    get;
    set;
}
<property><specifier>static</specifier> <type><name>string</name></type> <name>Name</name> <block>{
    <function_decl><name>get</name>;</function_decl>
    <function_decl><name>set</name>;</function_decl>
}</block></property>
class foo {
    static foo() { 
    }
}
<class>class <name>foo</name> <block>{
    <constructor><specifier>static</specifier> <name>foo</name><parameter_list>()</parameter_list> <block>{ 
    }</block></constructor>
}</block></class>

volatile


Element

XPath Query

  • volatile variables

    //src:decl[src:type/src:specifier ='volatile']

Example

volatile int foo; 
int volatile foo;
<decl_stmt><decl><type><specifier>volatile</specifier> <name>int</name></type> <name>foo</name></decl>;</decl_stmt> 
<decl_stmt><decl><type><name>int</name> <specifier>volatile</specifier></type> <name>foo</name></decl>;</decl_stmt>

ref


Element

XPath Query

  • functions with ref parameters

    //src:function[src:parameter_list/src:parameter/src:decl/src:type/src:modifier[.='ref']]

Example

void Swap(ref int x, ref int y){
}
<function><type><name>void</name></type> <name>Swap</name><parameter_list>(<parameter><decl><type><modifier>ref</modifier> <name>int</name></type> <name>x</name></decl></parameter>, <parameter><decl><type><modifier>ref</modifier> <name>int</name></type> <name>y</name></decl></parameter>)</parameter_list><block>{
}</block></function>

params


Element

XPath Query

  • functions with a variable number of arguments

    //src:function[src:parameter_list/src:parameter/src:decl/src:type/src:specifier[.='params']]

Example

void F(params int[] args) {
}
<function><type><name>void</name></type> <name>F</name><parameter_list>(<parameter><decl><type><specifier>params</specifier> <name><name>int</name><index>[]</index></name></type> <name>args</name></decl></parameter>)</parameter_list> <block>{
}</block></function>

extern specifier


Element

XPath Query

  • extern functions declarations

    //src:function_decl[src:type/src:specifier [.='extern']]

Example

[DllImport("avifil32.dll")]
private static extern void AVIFileInit();
<function_decl><attribute>[<expr><call><name>DllImport</name><argument_list>(<argument><expr><literal type="string">"avifil32.dll"</literal></expr></argument>)</argument_list></call></expr>]</attribute>
<specifier>private</specifier> <specifier>static</specifier> <specifier>extern</specifier> <type><name>void</name></type> <name>AVIFileInit</name><parameter_list>()</parameter_list>;</function_decl>

virtual


Element

XPath Query

  • virtual functions

    //src:function[src:type/src:specifier [.='virtual']]

Example

virtual double Area() 
{
}
<function><specifier>virtual</specifier> <type><name>double</name></type> <name>Area</name><parameter_list>()</parameter_list> 
<block>{
}</block></function>

override


Element

XPath Query

  • overridden functions

    //src:function[src:type/src:specifier [.='override']]

Example

override double area() {
}
<function><specifier>override</specifier> <type><name>double</name></type> <name>area</name><parameter_list>()</parameter_list> <block>{
}</block></function>

new


Element

XPath Query

  • functions which hide a previous implementation using new

    //src:function[src:type/src:specifier [.='new']]

Example

public new void Invoke() { }
<function><specifier>public</specifier> <specifier>new</specifier> <type><name>void</name></type> <name>Invoke</name><parameter_list>()</parameter_list> <block>{ }</block></function>

sealed


Element

XPath Queries

  • sealed classes

    //src:class[src:specifier [.='sealed']]
  • sealed methods

    //src:function[src:type/src:specifier [.='sealed']]

Examples

sealed class Foo {
}
<class><specifier>sealed</specifier> class <name>Foo</name> <block>{
}</block></class>
sealed override double area() {  }
<function><specifier>sealed</specifier> <specifier>override</specifier> <type><name>double</name></type> <name>area</name><parameter_list>()</parameter_list> <block>{  }</block></function>

async


Element

XPath Query

  • async methods

    //src:function[src:type/src:specifier [.='async']]

Example

async Task ExampleMethodAsync();
<function_decl><specifier>async</specifier> <type><name>Task</name></type> <name>ExampleMethodAsync</name><parameter_list>()</parameter_list>;</function_decl>

partial


Element

XPath Queries

  • partial classes

    //src:class[src:specifier [.='partial']]
  • partial functions

    //src:function[src:type/src:specifier [.='partial']]
  • partial function declarations

    //src:function_decl[src:type/src:specifier [.='partial']]

Examples

partial class Employee;
<class_decl><specifier>partial</specifier> class <name>Employee</name>;</class_decl>
partial void OnSomethingHappened(String s);

partial void OnSomethingHappened(String s) {
}
<function_decl><specifier>partial</specifier> <type><name>void</name></type> <name>OnSomethingHappened</name><parameter_list>(<parameter><decl><type><name>String</name></type> <name>s</name></decl></parameter>)</parameter_list>;</function_decl>

<function><specifier>partial</specifier> <type><name>void</name></type> <name>OnSomethingHappened</name><parameter_list>(<parameter><decl><type><name>String</name></type> <name>s</name></decl></parameter>)</parameter_list> <block>{
}</block></function>

explicit


Element

XPath Query

  • explicit conversion operators

    //src:function[src:type/src:specifier [.='explicit']]

Example

static explicit operator Celsius(Fahrenheit fahr) {
}
<function type="operator"><specifier>static</specifier> <specifier>explicit</specifier> <name>operator <name>Celsius</name></name><parameter_list>(<parameter><decl><type><name>Fahrenheit</name></type> <name>fahr</name></decl></parameter>)</parameter_list> <block>{
}</block></function>

implicit


Element

XPath Query

  • implicit conversion operators

    //src:function[src:type/src:specifier [.='implicit']]

Example

static implicit operator byte(Digit d) {
}
<function type="operator"><specifier>static</specifier> <specifier>implicit</specifier> <name>operator <name>byte</name></name><parameter_list>(<parameter><decl><type><name>Digit</name></type> <name>d</name></decl></parameter>)</parameter_list> <block>{
}</block></function>

yield


Element

XPath Queries

  • yield statements

    //src:specifier[.='yield']
  • yield-return statements

    //src:return[src:specifier[.='yield']]
  • yield-break statements

    //src:break[src:specifier[.='yield']]

Examples

yield return result;
<return><specifier>yield</specifier> return <expr><name>result</name></expr>;</return>
yield break;
<break><specifier>yield</specifier> break;</break>

this (extension methods)


Element

XPath Query

  • extension methods

    //src:function[src:parameter_list/src:parameter/src:decl/src:type/src:specifier[.='this']]

Example

static int WordCount(this String str)
{
}
<function><specifier>static</specifier> <type><name>int</name></type> <name>WordCount</name><parameter_list>(<parameter><decl><type><specifier>this</specifier> <name>String</name></type> <name>str</name></decl></parameter>)</parameter_list>
<block>{
}</block></function>

nullable variable modifier


Element

Subelements

XPath Query

  • nullable variable declarations

    //src:decl[src:type/src:modifier[.='?']]

Example

int? i = null;
<decl_stmt><decl><type><name>int</name><modifier>?</modifier></type> <name>i</name> <init>= <expr><literal type="null">null</literal></expr></init></decl>;</decl_stmt>

array declaration


Element

Subelements

XPath Query

  • explicit array declarations

    //src:decl[src:type/src:name/src:index]

Examples

int[] numbers = new int[5];
<decl_stmt><decl><type><name><name>int</name><index>[]</index></name></type> <name>numbers</name> <init>= <expr><operator>new</operator> <name><name>int</name><index>[<expr><literal type="number">5</literal></expr>]</index></name></expr></init></decl>;</decl_stmt>
string[] names = new string[3] {"Matt", "Joanne", "Robert"};
<decl_stmt><decl><type><name><name>string</name><index>[]</index></name></type> <name>names</name> <init>= <expr><operator>new</operator> <name><name>string</name><index>[<expr><literal type="number">3</literal></expr>]</index></name> <block>{<expr><literal type="string">"Matt"</literal></expr>, <expr><literal type="string">"Joanne"</literal></expr>, <expr><literal type="string">"Robert"</literal></expr>}</block></expr></init></decl>;</decl_stmt>
string[,] siblings = new string[2, 2] { {"Mike","Amy"}, {"Mary","Albert"} };
<decl_stmt><decl><type><name><name>string</name><index>[<expr/>,<expr/>]</index></name></type> <name>siblings</name> <init>= <expr><operator>new</operator> <name><name>string</name><index>[<expr><literal type="number">2</literal></expr>, <expr><literal type="number">2</literal></expr>]</index></name> <block>{ <expr><block>{<expr><literal type="string">"Mike"</literal></expr>,<expr><literal type="string">"Amy"</literal></expr>}</block></expr>, <expr><block>{<expr><literal type="string">"Mary"</literal></expr>,<expr><literal type="string">"Albert"</literal></expr>}</block></expr> }</block></expr></init></decl>;</decl_stmt>
int[][] numbers = new int[2][] { new int[] {2,3,4}, new int[] {5,6,7,8,9} };
<decl_stmt><decl><type><name><name>int</name><index>[]</index><index>[]</index></name></type> <name>numbers</name> <init>= <expr><operator>new</operator> <name><name>int</name><index>[<expr><literal type="number">2</literal></expr>]</index><index>[]</index></name> <block>{ <expr><operator>new</operator> <name><name>int</name><index>[]</index></name> <block>{<expr><literal type="number">2</literal></expr>,<expr><literal type="number">3</literal></expr>,<expr><literal type="number">4</literal></expr>}</block></expr>, <expr><operator>new</operator> <name><name>int</name><index>[]</index></name> <block>{<expr><literal type="number">5</literal></expr>,<expr><literal type="number">6</literal></expr>,<expr><literal type="number">7</literal></expr>,<expr><literal type="number">8</literal></expr>,<expr><literal type="number">9</literal></expr>}</block></expr> }</block></expr></init></decl>;</decl_stmt>
int[][] numbers = { new int[] {2,3,4}, new int[] {5,6,7,8,9} };
<decl_stmt><decl><type><name><name>int</name><index>[]</index><index>[]</index></name></type> <name>numbers</name> <init>= <expr><block>{ <expr><operator>new</operator> <name><name>int</name><index>[]</index></name> <block>{<expr><literal type="number">2</literal></expr>,<expr><literal type="number">3</literal></expr>,<expr><literal type="number">4</literal></expr>}</block></expr>, <expr><operator>new</operator> <name><name>int</name><index>[]</index></name> <block>{<expr><literal type="number">5</literal></expr>,<expr><literal type="number">6</literal></expr>,<expr><literal type="number">7</literal></expr>,<expr><literal type="number">8</literal></expr>,<expr><literal type="number">9</literal></expr>}</block></expr> }</block></expr></init></decl>;</decl_stmt>

implicitly typed arrays

var b = new[] { "hello", null, "world" };
<decl_stmt><decl><type><name>var</name></type> <name>b</name> <init>= <expr><operator>new</operator><index>[]</index> <block>{ <expr><literal type="string">"hello"</literal></expr>, <expr><literal type="null">null</literal></expr>, <expr><literal type="string">"world"</literal></expr> }</block></expr></init></decl>;</decl_stmt>

function declaration


Element

Subelements

XPath Queries

  • function declarations

    //src:function_decl
  • function-declaration return types

    //src:function_decl/src:type
  • function-declaration parameters

    //src:function_decl/src:parameter_list/src:parameter
  • function declarations with only two parameters

    //src:function_decl[src:parameter_list[count(src:parameter) = 2]]
  • function-declaration names

    //src:function_decl/src:name

Example

void doWork();
<function_decl><type><name>void</name></type> <name>doWork</name><parameter_list>()</parameter_list>;</function_decl>

function definition


Element

Subelements

XPath Queries

  • function definitions

    //src:function
  • function-definition return types

    //src:function/src:type
  • function-definition parameters

    //src:function/src:parameter_list/src:parameter
  • function definitions with only two parameters

    //src:function[src:parameter_list[count(src:parameter) = 2]]

Example

void doWork() {
}
<function><type><name>void</name></type> <name>doWork</name><parameter_list>()</parameter_list> <block>{
}</block></function>

default arguments


Element

Subelement

XPath Query

  • function declarations with default parameters

    //src:function_decl[src:parameter_list/src:parameter/src:decl/src:init]

Example

void ExampleMethod(int required, string optionalstr = "default string", int optionalint = 10) {
}
<function><type><name>void</name></type> <name>ExampleMethod</name><parameter_list>(<parameter><decl><type><name>int</name></type> <name>required</name></decl></parameter>, <parameter><decl><type><name>string</name></type> <name>optionalstr</name> <init>= <expr><literal type="string">"default string"</literal></expr></init></decl></parameter>, <parameter><decl><type><name>int</name></type> <name>optionalint</name> <init>= <expr><literal type="number">10</literal></expr></init></decl></parameter>)</parameter_list> <block>{
}</block></function>

delegate type definition


Element

Subelements

XPath Query

  • delegate declarations

    //src:function_decl[src:type/src:specifier[.='delegate']]

Example

delegate int PerformCalculation(int x, int y);
<function_decl><specifier>delegate</specifier> <type><name>int</name></type> <name>PerformCalculation</name><parameter_list>(<parameter><decl><type><name>int</name></type> <name>x</name></decl></parameter>, <parameter><decl><type><name>int</name></type> <name>y</name></decl></parameter>)</parameter_list>;</function_decl>

namespace


Element

Subelements

XPath Query

  • namespaces

    //src:namespace

Example

namespace SampleNamespace
{
}
<namespace>namespace <name>SampleNamespace</name>
<block>{
}</block></namespace>

using directive


Element

Subelements

XPath Query

  • using directives

    //src:using

Examples

using System.Text;
<using>using <name><name>System</name><operator>.</operator><name>Text</name></name>;</using>
using Project = PC.MyCompany.Project;
<using>using <name>Project</name> <init>= <expr><name><name>PC</name><operator>.</operator><name>MyCompany</name><operator>.</operator><name>Project</name></name></expr></init>;</using>

extern alias


Element

XPath Query

  • external alias declarations

    //src:extern[src:specifier[.='alias']]

Example

extern alias GridV1;
<extern>extern <specifier>alias</specifier> <name>GridV1</name>;</extern>

operator overloading


Element

Subelements

XPath Query

  • operator declarations

    //src:function_decl[-type='operator']

Example

public static Complex operator +(Complex c1, Complex c2) 
{
}
<function type="operator"><specifier>public</specifier> <specifier>static</specifier> <type><name>Complex</name></type> <name>operator <name>+</name></name><parameter_list>(<parameter><decl><type><name>Complex</name></type> <name>c1</name></decl></parameter>, <parameter><decl><type><name>Complex</name></type> <name>c2</name></decl></parameter>)</parameter_list> 
<block>{
}</block></function>

implicit conversion operator definition


Element

Subelements

XPath Query

  • implicit conversion operator definition overloads

    //src:function[-type='operator'][src:type/src:specifier[.='implicit']]

Examples

public static implicit operator Digit(double d)
{
}
<function type="operator"><specifier>public</specifier> <specifier>static</specifier> <specifier>implicit</specifier> <name>operator <name>Digit</name></name><parameter_list>(<parameter><decl><type><name>double</name></type> <name>d</name></decl></parameter>)</parameter_list>
<block>{
}</block></function>
public static implicit operator double(Digit d)
{
}
<function type="operator"><specifier>public</specifier> <specifier>static</specifier> <specifier>implicit</specifier> <name>operator <name>double</name></name><parameter_list>(<parameter><decl><type><name>Digit</name></type> <name>d</name></decl></parameter>)</parameter_list>
<block>{
}</block></function>

explicit conversion operator definition


Element

Subelements

XPath Query

  • explicit conversion operator overloads

    //src:function[-type='operator'][src:type/src:specifier[.='explicit']]

Example

public static explicit operator Celsius(Fahrenheit fahr)
{
}
<function type="operator"><specifier>public</specifier> <specifier>static</specifier> <specifier>explicit</specifier> <name>operator <name>Celsius</name></name><parameter_list>(<parameter><decl><type><name>Fahrenheit</name></type> <name>fahr</name></decl></parameter>)</parameter_list>
<block>{
}</block></function>

operator false


Element

Subelements

XPath Query

  • false operator overloads

    //src:function[-type='operator'][src:name/src:name[.='false']]

Example

public static bool operator false(DBBool x) {
}
<function type="operator"><specifier>public</specifier> <specifier>static</specifier> <type><name>bool</name></type> <name>operator <name>false</name></name><parameter_list>(<parameter><decl><type><name>DBBool</name></type> <name>x</name></decl></parameter>)</parameter_list> <block>{
}</block></function>

operator true


Element

Subelements

XPath Query

  • true operator overloads

    //src:function[-type='operator'][src:name/src:name[.='true']]

Example

public static bool operator true(DBBool x) {
}
<function type="operator"><specifier>public</specifier> <specifier>static</specifier> <type><name>bool</name></type> <name>operator <name>true</name></name><parameter_list>(<parameter><decl><type><name>DBBool</name></type> <name>x</name></decl></parameter>)</parameter_list> <block>{
}</block></function>

pointer declaration


Element

XPath Query

  • of the declarations of pointers

    //src:decl[src:type/src:modifier[.='*']]

Example

int* i = &x;
<decl_stmt><decl><type><name>int</name><modifier>*</modifier></type> <name>i</name> <init>= <expr><operator>&amp;</operator><name>x</name></expr></init></decl>;</decl_stmt>

class


Element

Subelements

XPath Queries

  • class definitions

    //src:class
  • classes with the name foo

    //src:class[src:name[.='foo']]
  • functions within classes

    //src:function[ancestor::src:class]
  • function declarations within classes

    //src:function_decl[ancestor::src:class]

Examples

class TestClass
{
}
<class>class <name>TestClass</name>
<block>{
}</block></class>
class TestClass2
    :BaseClass, IInterface1, IInterface2
{
}
<class>class <name>TestClass2</name>
    <super>:<name>BaseClass</name>, <name>IInterface1</name>, <name>IInterface2</name></super>
<block>{
}</block></class>

struct


Element

Subelements

XPath Queries

  • structs

    //src:struct
  • struct members

    //src:struct/src:block/src:decl_stmt

Examples

struct Book
{
}
<struct>struct <name>Book</name>
<block>{
}</block></struct>
struct Book
    :ISortable<Book>
{
}
<struct>struct <name>Book</name>
    <super>:<name><name>ISortable</name><argument_list type="generic">&lt;<argument><name>Book</name></argument>&gt;</argument_list></name></super>
<block>{
}</block></struct>

interface


Element

Subelements

XPath Query

  • interfaces

    //src:interface

Examples

interface IInterfaceExample
{
}
<interface>interface <name>IInterfaceExample</name>
<block>{
}</block></interface>
interface IInterfaceExample
    :ISortable, IComparable
{
}
<interface>interface <name>IInterfaceExample</name>
    <super>:<name>ISortable</name>, <name>IComparable</name></super>
<block>{
}</block></interface>

anonymous type


Element

Subelement

XPath Query

  • expressions that contain an anonymous class

    //src:expr[src:operator[.='new']/following-sibling::src:block]

Example

var v = new { Amount = 108, Message = "Hello" };
<decl_stmt><decl><type><name>var</name></type> <name>v</name> <init>= <expr><operator>new</operator> <block>{ <expr><name>Amount</name> <operator>=</operator> <literal type="number">108</literal></expr>, <expr><name>Message</name> <operator>=</operator> <literal type="string">"Hello"</literal></expr> }</block></expr></init></decl>;</decl_stmt>

get


Element

Subelements

XPath Query

  • get functions with their own implementation

    //src:function[src:name[.='get']]

Example

get {
    return x;
}
<function><name>get</name> <block>{
    <return>return <expr><name>x</name></expr>;</return>
}</block></function>

get (default implementation)


Element

Subelement

XPath Query

  • default implemented get definitions

    //src:function_decl[src:name[.='get']]

Example

get;
<function_decl><name>get</name>;</function_decl>

set


Element

Subelements

XPath Query

  • set definitions

    //src:function[src:name[.='set']]

Example

set {
    x = value;
}
<function><name>set</name> <block>{
    <expr_stmt><expr><name>x</name> <operator>=</operator> <name>value</name></expr>;</expr_stmt>
}</block></function>

set (default implementation)


Element

Subelement

XPath Query

  • default implemented set definitions

    //src:function_decl[src:name[.='set']]

Example

set;
<function_decl><name>set</name>;</function_decl>

event


Element

Subelements

XPath Query

  • events

    //src:event

Examples

public event SampleEventHandler SampleEvent;
<event><specifier>public</specifier> event <type><name>SampleEventHandler</name></type> <name>SampleEvent</name>;</event>
event EventHandler IDrawingObject.OnDraw
{
    add
    {
        PreDrawEvent += value;
    }
    remove
    {
        PreDrawEvent -= value;
    }
}
<event>event <type><name>EventHandler</name></type> <name><name>IDrawingObject</name><operator>.</operator><name>OnDraw</name></name>
<block>{
    <function><name>add</name>
    <block>{
        <expr_stmt><expr><name>PreDrawEvent</name> <operator>+=</operator> <name>value</name></expr>;</expr_stmt>
    }</block></function>
    <function><name>remove</name>
    <block>{
        <expr_stmt><expr><name>PreDrawEvent</name> <operator>-=</operator> <name>value</name></expr>;</expr_stmt>
    }</block></function>
}</block></event>

add


Element

Subelements

XPath Query

  • add definitions

    //src:function[src:name[.='add']]

Example

add {
    otherEvent += value;
}
<function><name>add</name> <block>{
    <expr_stmt><expr><name>otherEvent</name> <operator>+=</operator> <name>value</name></expr>;</expr_stmt>
}</block></function>

remove


Element

Subelements

XPath Query

  • remove definitions

    //src:function[src:name[.='remove']]

Example

remove {
    otherEvent -= value;
}
<function><name>remove</name> <block>{
    <expr_stmt><expr><name>otherEvent</name> <operator>-=</operator> <name>value</name></expr>;</expr_stmt>
}</block></function>

inheritance list


Element

Subelements

XPath Queries

  • classes with at least one super class

    //src:class[src:super]
  • classes that inherit from bar

    //src:class[src:super/src:name[. = 'bar']]

Example

class Foo
    :Bar
{
}
<class>class <name>Foo</name>
    <super>:<name>Bar</name></super>
<block>{
}</block></class>

constructor


Element

Subelements

XPath Queries

  • constructors

    //src:constructor
  • constructors with no parameters

    //src:constructor[src:parameter_list[not(src:parameter)]]
  • possible default constructors, including constructors with all default parameters

    //src:constructor[src:parameter_list[not(src:parameter)] or (count(src:parameter_list/src:parameter) = count(src:parameter_list/src:parameter/src:decl/src:init))]

Example

class Foo {
    Foo() {
    }
}
<class>class <name>Foo</name> <block>{
    <constructor><name>Foo</name><parameter_list>()</parameter_list> <block>{
    }</block></constructor>
}</block></class>

this (constructor forwarding)


Element

XPath Query

  • constructors which forward to the another constructor using this

    //src:constructor[src:member_list/src:call/src:name = 'this']

Example

class Foo {
    Foo()
        :this("")
    {
    }
}
<class>class <name>Foo</name> <block>{
    <constructor><name>Foo</name><parameter_list>()</parameter_list>
        <member_init_list>:<call><name>this</name><argument_list>(<argument><expr><literal type="string">""</literal></expr></argument>)</argument_list></call>
    </member_init_list><block>{
    }</block></constructor>
}</block></class>

base (constructor selection)


Element

XPath Query

  • constructors which forward to a base classes constructor

    //src:constructor[src:member_list/src:call/src:name = 'base']

Example

class Foo {
    Foo()
        :base("")
    {
    }
}
<class>class <name>Foo</name> <block>{
    <constructor><name>Foo</name><parameter_list>()</parameter_list>
        <member_init_list>:<call><name>base</name><argument_list>(<argument><expr><literal type="string">""</literal></expr></argument>)</argument_list></call>
    </member_init_list><block>{
    }</block></constructor>
}</block></class>

destructor


Element

Subelement

XPath Query

  • destructors

    //src:destructor

Example

~Foo()
{
}
<destructor><name>~<name>Foo</name></name><parameter_list>()</parameter_list>
<block>{
}</block></destructor>

object initializer


Element

Subelements

XPath Query

  • object initializations, this excludes array initialization

    //src:decl[src:init/src:expr/src:block]

Example

Cat cat = new Cat { Age = 10, Name = "Fluffy" };
<decl_stmt><decl><type><name>Cat</name></type> <name>cat</name> <init>= <expr><operator>new</operator> <name>Cat</name> <block>{ <expr><name>Age</name> <operator>=</operator> <literal type="number">10</literal></expr>, <expr><name>Name</name> <operator>=</operator> <literal type="string">"Fluffy"</literal></expr> }</block></expr></init></decl>;</decl_stmt>

disambiguating function override


Element

Subelements

XPath Query

  • disambiguating function overrides

    //src:function[src:name[src:name][src:operator[.='.']]]

Example

int IComparable.CompareTo(object other) {
}
<function><type><name>int</name></type> <name><name>IComparable</name><operator>.</operator><name>CompareTo</name></name><parameter_list>(<parameter><decl><type><name>object</name></type> <name>other</name></decl></parameter>)</parameter_list> <block>{
}</block></function>

named parameters


Element

Subelements

XPath Query

  • function calls with named parameters

    //src:call[src:argument_list/src:argument/src:name]

Example

CalculateBMI(height: 64, weight: 123);
<expr_stmt><expr><call><name>CalculateBMI</name><argument_list>(<argument><name>height</name>: <expr><literal type="number">64</literal></expr></argument>, <argument><name>weight</name>: <expr><literal type="number">123</literal></expr></argument>)</argument_list></call></expr>;</expr_stmt>

stackalloc


Element

XPath Query

  • expressions which call stackalloc

    //src:operator[.='stackalloc']

Example

int* block = stackalloc int[100];
<decl_stmt><decl><type><name>int</name><modifier>*</modifier></type> <name>block</name> <init>= <expr><operator>stackalloc</operator> <name><name>int</name><index>[<expr><literal type="number">100</literal></expr>]</index></name></expr></init></decl>;</decl_stmt>

dereference member access


Element

Subelements

XPath Query

  • uses of the -> operator

    //src:operator[.='->']

Example

 t->tm_sec;
 <expr_stmt><expr><name><name>t</name><operator>-&gt;</operator><name>tm_sec</name></name></expr>;</expr_stmt>

member and scope access


Element

Subelements

XPath Query

  • uses of the . operator

    //src:operator[.='.']

Example

t.tm_sec;
<expr_stmt><expr><name><name>t</name><operator>.</operator><name>tm_sec</name></name></expr>;</expr_stmt>

base (object)


Element

XPath Query

  • uses of base

    //src:name[.='base']

Example

base.Invoke();
<expr_stmt><expr><call><name><name>base</name><operator>.</operator><name>Invoke</name></name><argument_list>()</argument_list></call></expr>;</expr_stmt>

default (object construction)


Element

Subelement

XPath Query

  • uses of default, where default is used to default construct an object

    //src:default[src:argument_list]

Example

T temp = default(T);
<decl_stmt><decl><type><name>T</name></type> <name>temp</name> <init>= <expr><default>default<argument_list>(<argument><expr><name>T</name></expr></argument>)</argument_list></default></expr></init></decl>;</decl_stmt>

checked


Element

Subelement

XPath Queries

  • uses of checked, in both a statement and expression form

    //src:checked
  • uses of checked when it’s used as an expression

    //src:checked[not(src:block)]
  • uses of the checked statement

    //src:checked[src:block]

Examples

checked {
    int i3 = 2147483647 + ten;
    Console.WriteLine(i3);
}
<checked>checked <block>{
    <decl_stmt><decl><type><name>int</name></type> <name>i3</name> <init>= <expr><literal type="number">2147483647</literal> <operator>+</operator> <name>ten</name></expr></init></decl>;</decl_stmt>
    <expr_stmt><expr><call><name><name>Console</name><operator>.</operator><name>WriteLine</name></name><argument_list>(<argument><expr><name>i3</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
}</block></checked>
z = checked(maxIntValue + 10);
<expr_stmt><expr><name>z</name> <operator>=</operator> <checked>checked<argument_list>(<argument><expr><name>maxIntValue</name> <operator>+</operator> <literal type="number">10</literal></expr></argument>)</argument_list></checked></expr>;</expr_stmt>

unchecked


Element

Subelement

XPath Queries

  • uses of unchecked, in both statement and expression form

    //src:unchecked
  • uses of unchecked used as an expression

    //src:unchecked[not(src:block)]
  • uses of the unchecked statement

    //src:unchecked[src:block]

Examples

unchecked {
    int i3 = 2147483647 + ten;
    Console.WriteLine(i3);
}
<unchecked>unchecked <block>{
    <decl_stmt><decl><type><name>int</name></type> <name>i3</name> <init>= <expr><literal type="number">2147483647</literal> <operator>+</operator> <name>ten</name></expr></init></decl>;</decl_stmt>
    <expr_stmt><expr><call><name><name>Console</name><operator>.</operator><name>WriteLine</name></name><argument_list>(<argument><expr><name>i3</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
}</block></unchecked>
z = unchecked(maxIntValue + 10);
<expr_stmt><expr><name>z</name> <operator>=</operator> <unchecked>unchecked<argument_list>(<argument><expr><name>maxIntValue</name> <operator>+</operator> <literal type="number">10</literal></expr></argument>)</argument_list></unchecked></expr>;</expr_stmt>

var


Element

XPath Query

  • var types

    //src:type[src:name[.='var']]

Example

var x = 5;
<decl_stmt><decl><type><name>var</name></type> <name>x</name> <init>= <expr><literal type="number">5</literal></expr></init></decl>;</decl_stmt>

string keyword


Element

XPath Query

  • uses of the string keyword

    //src:name[.='string']

Example

string x = "banana";
<decl_stmt><decl><type><name>string</name></type> <name>x</name> <init>= <expr><literal type="string">"banana"</literal></expr></init></decl>;</decl_stmt>

global


Element

Subelements

XPath Query

  • uses of global as part of a complex name

    //src:name[src:name[.='global']]

Example

global::TestApp app;
<decl_stmt><decl><type><name><name>global</name><operator>::</operator><name>TestApp</name></name></type> <name>app</name></decl>;</decl_stmt>

generic variable declaration


Element

Subelement

XPath Query

  • declarations of generic variables

    //src:decl[src:type/src:name/src:argument_list]

Example

List<int> x;
<decl_stmt><decl><type><name><name>List</name><argument_list type="generic">&lt;<argument><name>int</name></argument>&gt;</argument_list></name></type> <name>x</name></decl>;</decl_stmt>

generic class


Element

Subelements

XPath Query

  • generic classes

    //src:class[src:name/src:argument_list]

Example

class NodeConcrete<T> { }
<class>class <name><name>NodeConcrete</name><argument_list type="generic">&lt;<argument><name>T</name></argument>&gt;</argument_list></name> <block>{ }</block></class>

in (generic parameter constraint)


Element

XPath Query

  • generic parameters constrained with in

    //src:argument[src:specifier[.='in']][parent::src:argument_list[-type='template']]

Example

interface IContravariant<in A> { }
<interface>interface <name><name>IContravariant</name><argument_list type="generic">&lt;<argument><specifier>in</specifier> <name>A</name></argument>&gt;</argument_list></name> <block>{ }</block></interface>

out (generic parameter constraint)


Element

XPath Query

  • generic parameters constrained with out

    //src:argument[src:specifier[.='out']][parent::src:argument_list[-type='template']]

Example

class Conversion<out A> { }
<class>class <name><name>Conversion</name><argument_list type="generic">&lt;<argument><specifier>out</specifier> <name>A</name></argument>&gt;</argument_list></name> <block>{ }</block></class>

new (constraint)


Element

XPath Queries

  • uses of the new constraint

    //src:constraint[src:name = 'new']
  • classes which specify the new constraint

    //src:class[src:where/src:constraint/src:name = 'new']

Example

class Foo<T> where T : new()
{}
<class>class <name><name>Foo</name><argument_list type="generic">&lt;<argument><name>T</name></argument>&gt;</argument_list></name> <where>where <name>T</name> : <constraint><name>new</name>()</constraint></where>
<block>{}</block></class>

class (constraint)


Element

XPath Query

  • classes which use a class constraint

    //src:class[src:where/src:constraint.='class']

Example

class Foo<T> where T : class
{}
<class>class <name><name>Foo</name><argument_list type="generic">&lt;<argument><name>T</name></argument>&gt;</argument_list></name> <where>where <name>T</name> : <constraint>class</constraint></where>
<block>{}</block></class>

struct (constraint)


Element

XPath Query

  • generic methods that specify a struct constraint

    //src:function[src:where/src:constraint.='struct']

Example

void foo<X>(X x) where X : struct
{ }
<function><type><name>void</name></type> <name><name>foo</name><argument_list type="generic">&lt;<argument><name>X</name></argument>&gt;</argument_list></name><parameter_list>(<parameter><decl><type><name>X</name></type> <name>x</name></decl></parameter>)</parameter_list> <where>where <name>X</name> : <constraint>struct</constraint></where>
<block>{ }</block></function>

throw


Element

Subelement

XPath Query

  • uses of throw

    //src:throw

Examples

throw new MyException();
<throw>throw <expr><operator>new</operator> <call><name>MyException</name><argument_list>()</argument_list></call></expr>;</throw>
throw;
<throw>throw;</throw>

try


Element

Subelements

XPath Query

  • try blocks

    //src:try

Example

try
{
}
<try>try
<block>{
}</block></try>

catch


Element

Subelement

XPath Query

  • catch blocks

    //src:catch

Examples

try
{
}
catch
{
}
<try>try
<block>{
}</block>
<catch>catch
<block>{
}</block></catch></try>
try
{
}
catch(Exception e)
{
}
<try>try
<block>{
}</block>
<catch>catch<parameter_list>(<parameter><decl><type><name>Exception</name></type> <name>e</name></decl></parameter>)</parameter_list>
<block>{
}</block></catch></try>

finally


Element

Subelement

XPath Query

  • finally blocks

    //src:finally

Example

try { }
finally { }
<try>try <block>{ }</block>
<finally>finally <block>{ }</block></finally></try>

group


Element

Subelements

XPath Query

  • group clauses

    //src:group

Examples

var studentQuery1 =
    from student in students
    group student by student.Last[0];
<decl_stmt><decl><type><name>var</name></type> <name>studentQuery1</name> <init>=
    <expr><linq><from>from <expr><name>student</name></expr> <in>in <expr><name>students</name></expr></in></from>
    <group>group <expr><name>student</name></expr> <by>by <expr><name><name>student</name><operator>.</operator><name>Last</name><index>[<expr><literal type="number">0</literal></expr>]</index></name></expr></by></group></linq></expr></init></decl>;</decl_stmt>
var studentQuery2 =
    from student in students
    group student by student.Last[0] into g
    orderby g.Key
    select g;
<decl_stmt><decl><type><name>var</name></type> <name>studentQuery2</name> <init>=
    <expr><linq><from>from <expr><name>student</name></expr> <in>in <expr><name>students</name></expr></in></from>
    <group>group <expr><name>student</name></expr> <by>by <expr><name><name>student</name><operator>.</operator><name>Last</name><index>[<expr><literal type="number">0</literal></expr>]</index></name></expr></by> <into>into <expr><name>g</name></expr></into></group>
    <orderby>orderby <expr><name><name>g</name><operator>.</operator><name>Key</name></name></expr></orderby>
    <select>select <expr><name>g</name></expr></select></linq></expr></init></decl>;</decl_stmt>
group student by student.Last[0] into g
<expr><linq><group>group <expr><name>student</name></expr> <by>by <expr><name><name>student</name><operator>.</operator><name>Last</name><index>[<expr><literal type="number">0</literal></expr>]</index></name></expr></by> <into>into <expr><name>g</name></expr></into></group></linq></expr>

orderby


Element

Subelements

XPath Queries

  • uses of the orderby clause

    //src:orderby
  • uses of the orderby clause which sort in descending order

    //src:orderby[src:name[.='descending']]
  • uses of the orderby clause which sort in ascending order

    //src:orderby[src:name[.='ascending'] or not(src:name)]

Examples

IEnumerable<string> sortAscendingQuery =
    from fruit in fruits
    orderby fruit
    select fruit;
<decl_stmt><decl><type><name><name>IEnumerable</name><argument_list type="generic">&lt;<argument><name>string</name></argument>&gt;</argument_list></name></type> <name>sortAscendingQuery</name> <init>=
    <expr><linq><from>from <expr><name>fruit</name></expr> <in>in <expr><name>fruits</name></expr></in></from>
    <orderby>orderby <expr><name>fruit</name></expr></orderby>
    <select>select <expr><name>fruit</name></expr></select></linq></expr></init></decl>;</decl_stmt>
IEnumerable<string> sortDescendingQuery =
    from w in fruits
    orderby w descending 
    select w;
<decl_stmt><decl><type><name><name>IEnumerable</name><argument_list type="generic">&lt;<argument><name>string</name></argument>&gt;</argument_list></name></type> <name>sortDescendingQuery</name> <init>=
    <expr><linq><from>from <expr><name>w</name></expr> <in>in <expr><name>fruits</name></expr></in></from>
    <orderby>orderby <expr><name>w</name></expr> <name>descending</name></orderby> 
    <select>select <expr><name>w</name></expr></select></linq></expr></init></decl>;</decl_stmt>
IEnumerable<string> sortDescendingQuery =
    from w in fruits
    orderby w ascending 
    select w;  
<decl_stmt><decl><type><name><name>IEnumerable</name><argument_list type="generic">&lt;<argument><name>string</name></argument>&gt;</argument_list></name></type> <name>sortDescendingQuery</name> <init>=
    <expr><linq><from>from <expr><name>w</name></expr> <in>in <expr><name>fruits</name></expr></in></from>
    <orderby>orderby <expr><name>w</name></expr> <name>ascending</name></orderby> 
    <select>select <expr><name>w</name></expr></select></linq></expr></init></decl>;</decl_stmt>  

join


Element

Subelements

XPath Query

  • of the join clauses

    //src:join

Examples

inner join

var innerJoinQuery =
    from category in categories
    join prod in products on category.ID equals prod.CategoryID
    select new { ProductName = prod.Name, Category = category.Name };
<decl_stmt><decl><type><name>var</name></type> <name>innerJoinQuery</name> <init>=
    <expr><linq><from>from <expr><name>category</name></expr> <in>in <expr><name>categories</name></expr></in></from>
    <join>join <expr><name>prod</name></expr> <in>in <expr><name>products</name></expr></in> <on>on <expr><name><name>category</name><operator>.</operator><name>ID</name></name></expr></on> <equals>equals <expr><name><name>prod</name><operator>.</operator><name>CategoryID</name></name></expr></equals></join>
    <select>select <expr><operator>new</operator> <block>{ <expr><name>ProductName</name> <operator>=</operator> <name><name>prod</name><operator>.</operator><name>Name</name></name></expr>, <expr><name>Category</name> <operator>=</operator> <name><name>category</name><operator>.</operator><name>Name</name></name></expr> }</block></expr></select></linq></expr></init></decl>;</decl_stmt>

group join

var innerGroupJoinQuery =
    from category in categories
    join prod in products on category.ID equals prod.CategoryID into prodGroup
    select new { CategoryName = category.Name, Products = prodGroup };
<decl_stmt><decl><type><name>var</name></type> <name>innerGroupJoinQuery</name> <init>=
    <expr><linq><from>from <expr><name>category</name></expr> <in>in <expr><name>categories</name></expr></in></from>
    <join>join <expr><name>prod</name></expr> <in>in <expr><name>products</name></expr></in> <on>on <expr><name><name>category</name><operator>.</operator><name>ID</name></name></expr></on> <equals>equals <expr><name><name>prod</name><operator>.</operator><name>CategoryID</name></name></expr></equals> <into>into <expr><name>prodGroup</name></expr></into></join>
    <select>select <expr><operator>new</operator> <block>{ <expr><name>CategoryName</name> <operator>=</operator> <name><name>category</name><operator>.</operator><name>Name</name></name></expr>, <expr><name>Products</name> <operator>=</operator> <name>prodGroup</name></expr> }</block></expr></select></linq></expr></init></decl>;</decl_stmt>

subquery join

var innerGroupJoinQuery2 =
    from category in categories
    join prod in products on category.ID equals prod.CategoryID into prodGroup
    from prod2 in prodGroup
    where prod2.UnitPrice > 2.50M
    select prod2;
<decl_stmt><decl><type><name>var</name></type> <name>innerGroupJoinQuery2</name> <init>=
    <expr><linq><from>from <expr><name>category</name></expr> <in>in <expr><name>categories</name></expr></in></from>
    <join>join <expr><name>prod</name></expr> <in>in <expr><name>products</name></expr></in> <on>on <expr><name><name>category</name><operator>.</operator><name>ID</name></name></expr></on> <equals>equals <expr><name><name>prod</name><operator>.</operator><name>CategoryID</name></name></expr></equals> <into>into <expr><name>prodGroup</name></expr></into></join>
    <from>from <expr><name>prod2</name></expr> <in>in <expr><name>prodGroup</name></expr></in></from>
    <where>where <expr><name><name>prod2</name><operator>.</operator><name>UnitPrice</name></name> <operator>&gt;</operator> <literal type="number">2.50M</literal></expr></where>
    <select>select <expr><name>prod2</name></expr></select></linq></expr></init></decl>;</decl_stmt>

left outer join

var leftOuterJoinQuery =
    from category in categories
    join prod in products on category.ID equals prod.CategoryID into prodGroup
    from item in prodGroup.DefaultIfEmpty(new Product { Name = String.Empty, CategoryID = 0 })
    select new { CatName = category.Name, ProdName = item.Name };
<decl_stmt><decl><type><name>var</name></type> <name>leftOuterJoinQuery</name> <init>=
    <expr><linq><from>from <expr><name>category</name></expr> <in>in <expr><name>categories</name></expr></in></from>
    <join>join <expr><name>prod</name></expr> <in>in <expr><name>products</name></expr></in> <on>on <expr><name><name>category</name><operator>.</operator><name>ID</name></name></expr></on> <equals>equals <expr><name><name>prod</name><operator>.</operator><name>CategoryID</name></name></expr></equals> <into>into <expr><name>prodGroup</name></expr></into></join>
    <from>from <expr><name>item</name></expr> <in>in <expr><macro><name>prodGroup</name></macro><operator>.</operator><macro><name>DefaultIfEmpty</name><argument_list>(<argument>new Product { Name = String.Empty</argument>, <argument>CategoryID = <literal type="number">0</literal> }</argument>)</argument_list></macro></expr></in></from>
    <select>select <expr><operator>new</operator> <block>{ <expr><name>CatName</name> <operator>=</operator> <name><name>category</name><operator>.</operator><name>Name</name></name></expr>, <expr><name>ProdName</name> <operator>=</operator> <name><name>item</name><operator>.</operator><name>Name</name></name></expr> }</block></expr></select></linq></expr></init></decl>;</decl_stmt>

let


Element

Subelement

XPath Query

  • let clauses

    //src:let

Example

var earlyBirdQuery =
    from sentence in strings
    let words = sentence.Split(' ')
    from word in words
    let w = word.ToLower()
    where w[0] == 'a' || w[0] == 'e'
        || w[0] == 'i' || w[0] == 'o'
        || w[0] == 'u'
    select word;
<decl_stmt><decl><type><name>var</name></type> <name>earlyBirdQuery</name> <init>=
    <expr><linq><from>from <expr><name>sentence</name></expr> <in>in <expr><name>strings</name></expr></in></from>
    <let>let <expr><name>words</name> <operator>=</operator> <call><name><name>sentence</name><operator>.</operator><name>Split</name></name><argument_list>(<argument><expr><literal type="char">' '</literal></expr></argument>)</argument_list></call></expr></let>
    <from>from <expr><name>word</name></expr> <in>in <expr><name>words</name></expr></in></from>
    <let>let <expr><name>w</name> <operator>=</operator> <call><name><name>word</name><operator>.</operator><name>ToLower</name></name><argument_list>()</argument_list></call></expr></let>
    <where>where <expr><name><name>w</name><index>[<expr><literal type="number">0</literal></expr>]</index></name> <operator>==</operator> <literal type="char">'a'</literal> <operator>||</operator> <name><name>w</name><index>[<expr><literal type="number">0</literal></expr>]</index></name> <operator>==</operator> <literal type="char">'e'</literal>
        <operator>||</operator> <name><name>w</name><index>[<expr><literal type="number">0</literal></expr>]</index></name> <operator>==</operator> <literal type="char">'i'</literal> <operator>||</operator> <name><name>w</name><index>[<expr><literal type="number">0</literal></expr>]</index></name> <operator>==</operator> <literal type="char">'o'</literal>
        <operator>||</operator> <name><name>w</name><index>[<expr><literal type="number">0</literal></expr>]</index></name> <operator>==</operator> <literal type="char">'u'</literal></expr></where>
    <select>select <expr><name>word</name></expr></select></linq></expr></init></decl>;</decl_stmt>

#elif


Element

Subelements

XPath Query

  • elif directives

    //cpp:elif

Example

#if (DEBUG && !MYTEST)
        Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && MYTEST)
        Console.WriteLine("MYTEST is defined");
#elif (DEBUG && MYTEST)
        Console.WriteLine("DEBUG and MYTEST are defined");
#else
        Console.WriteLine("DEBUG and MYTEST are not defined");
#endif
<cpp:if>#<cpp:directive>if</cpp:directive> <expr><operator>(</operator><name>DEBUG</name> <operator>&amp;&amp;</operator> <operator>!</operator><name>MYTEST</name><operator>)</operator></expr></cpp:if>
        <expr_stmt><expr><call><name><name>Console</name><operator>.</operator><name>WriteLine</name></name><argument_list>(<argument><expr><literal type="string">"DEBUG is defined"</literal></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<cpp:elif>#<cpp:directive>elif</cpp:directive> <expr><operator>(</operator><operator>!</operator><name>DEBUG</name> <operator>&amp;&amp;</operator> <name>MYTEST</name><operator>)</operator></expr></cpp:elif>
        <expr_stmt><expr><call><name><name>Console</name><operator>.</operator><name>WriteLine</name></name><argument_list>(<argument><expr><literal type="string">"MYTEST is defined"</literal></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<cpp:elif>#<cpp:directive>elif</cpp:directive> <expr><operator>(</operator><name>DEBUG</name> <operator>&amp;&amp;</operator> <name>MYTEST</name><operator>)</operator></expr></cpp:elif>
        <expr_stmt><expr><call><name><name>Console</name><operator>.</operator><name>WriteLine</name></name><argument_list>(<argument><expr><literal type="string">"DEBUG and MYTEST are defined"</literal></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<cpp:else>#<cpp:directive>else</cpp:directive></cpp:else>
        <expr_stmt><expr><call><name><name>Console</name><operator>.</operator><name>WriteLine</name></name><argument_list>(<argument><expr><literal type="string">"DEBUG and MYTEST are not defined"</literal></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<cpp:endif>#<cpp:directive>endif</cpp:directive></cpp:endif>

#endif


Element

Subelement

XPath Query

  • endif directives

    //cpp:endif

Example

#if (DEBUG && !MYTEST)
        Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && MYTEST)
        Console.WriteLine("MYTEST is defined");
#elif (DEBUG && MYTEST)
        Console.WriteLine("DEBUG and MYTEST are defined");
#else
        Console.WriteLine("DEBUG and MYTEST are not defined");
#endif
<cpp:if>#<cpp:directive>if</cpp:directive> <expr><operator>(</operator><name>DEBUG</name> <operator>&amp;&amp;</operator> <operator>!</operator><name>MYTEST</name><operator>)</operator></expr></cpp:if>
        <expr_stmt><expr><call><name><name>Console</name><operator>.</operator><name>WriteLine</name></name><argument_list>(<argument><expr><literal type="string">"DEBUG is defined"</literal></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<cpp:elif>#<cpp:directive>elif</cpp:directive> <expr><operator>(</operator><operator>!</operator><name>DEBUG</name> <operator>&amp;&amp;</operator> <name>MYTEST</name><operator>)</operator></expr></cpp:elif>
        <expr_stmt><expr><call><name><name>Console</name><operator>.</operator><name>WriteLine</name></name><argument_list>(<argument><expr><literal type="string">"MYTEST is defined"</literal></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<cpp:elif>#<cpp:directive>elif</cpp:directive> <expr><operator>(</operator><name>DEBUG</name> <operator>&amp;&amp;</operator> <name>MYTEST</name><operator>)</operator></expr></cpp:elif>
        <expr_stmt><expr><call><name><name>Console</name><operator>.</operator><name>WriteLine</name></name><argument_list>(<argument><expr><literal type="string">"DEBUG and MYTEST are defined"</literal></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<cpp:else>#<cpp:directive>else</cpp:directive></cpp:else>
        <expr_stmt><expr><call><name><name>Console</name><operator>.</operator><name>WriteLine</name></name><argument_list>(<argument><expr><literal type="string">"DEBUG and MYTEST are not defined"</literal></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<cpp:endif>#<cpp:directive>endif</cpp:directive></cpp:endif>

#define


Element

Subelements

XPath Query

  • define directives

    //cpp:define

Example

#define DEBUG
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>DEBUG</name></cpp:macro></cpp:define>

#undef


Element

Subelements

XPath Query

  • undef directives

    //cpp:undef

Example

#undef TRACE
<cpp:undef>#<cpp:directive>undef</cpp:directive> <name>TRACE</name></cpp:undef>

#warning


Element

Subelement

XPath Query

  • warning directives

    //cpp:warning

Example

#warning Deprecated code in this method.
<cpp:warning>#<cpp:directive>warning</cpp:directive> Deprecated code in this method.</cpp:warning>

#error


Element

Subelement

XPath Query

  • error directives

    //cpp:error

Example

#error Deprecated code in this method.
<cpp:error>#<cpp:directive>error</cpp:directive> Deprecated code in this method.</cpp:error>

#region


Element

Subelements

XPath Query

  • region directives

    //cpp:region

Example

#region MyClass definition
public class MyClass 
{
    static void Main() 
    {
    }
}
#endregion
<cpp:region>#<cpp:directive>region</cpp:directive> <name>MyClass</name> <name>definition</name></cpp:region>
<class><specifier>public</specifier> class <name>MyClass</name> 
<block>{
    <function><specifier>static</specifier> <type><name>void</name></type> <name>Main</name><parameter_list>()</parameter_list> 
    <block>{
    }</block></function>
}</block></class>
<cpp:endregion>#<cpp:directive>endregion</cpp:directive></cpp:endregion>

#endregion


Element

Subelement

XPath Query

  • endregion directives

    //cpp:endregion

Example

#region MyClass definition
public class MyClass 
{
    static void Main() 
    {
    }
}
#endregion
<cpp:region>#<cpp:directive>region</cpp:directive> <name>MyClass</name> <name>definition</name></cpp:region>
<class><specifier>public</specifier> class <name>MyClass</name> 
<block>{
    <function><specifier>static</specifier> <type><name>void</name></type> <name>Main</name><parameter_list>()</parameter_list> 
    <block>{
    }</block></function>
}</block></class>
<cpp:endregion>#<cpp:directive>endregion</cpp:directive></cpp:endregion>

#pragma


Element

Subelements

XPath Query

  • pragma directives

    //cpp:pragma

Example

#pragma warning disable warning-list
<cpp:pragma>#<cpp:directive>pragma</cpp:directive> <name>warning</name> <name>disable</name> <name>warning</name><name>-</name><name>list</name></cpp:pragma>