- Syntax: do statement, else clause, fixed statement, for statement, foreach statement, if statement, lock statement, using statement, while statement
- Span: embedded statement
- Syntax: selected declarations
private object x;
private object y;
private object z;
private object x;
private object y;
private object z;
- Syntax: method, property, indexer, event
- Span: identifier
public class Foo : IFoo
{
public void Bar()
{
}
}
public interface IFoo
{
}
public class Foo : IFoo
{
public void Bar()
{
}
}
public interface IFoo
{
void Bar();
}
- Syntax: switch statement
switch (dayOfWeek)
{
case DayOfWeek.Sunday:
break;
case DayOfWeek.Monday:
break;
case DayOfWeek.Tuesday:
break;
case DayOfWeek.Wednesday:
break;
case DayOfWeek.Thursday:
break;
}
switch (dayOfWeek)
{
case DayOfWeek.Sunday:
break;
case DayOfWeek.Monday:
break;
case DayOfWeek.Tuesday:
break;
case DayOfWeek.Wednesday:
break;
case DayOfWeek.Thursday:
break;
case DayOfWeek.Friday:
break;
case DayOfWeek.Saturday:
break;
}
- Syntax: method declaration, indexer declaration
- Span: method name or 'this' keyword
interface IFoo
{
void Bar(object p);
}
class Foo : IFoo
{
public void Bar(object p, object p2)
{
}
}
interface IFoo
{
void Bar(object p, object p2);
}
class Foo : IFoo
{
public void Bar(object p, object p2)
{
}
}
- Syntax: selected word(s) in documentation comment
/// <summary>
/// null
/// </summary>
public class Foo
{
}
/// <summary>
/// <c>null</c>
/// </summary>
public class Foo
{
}
- Syntax: class declaration, struct declaration, interface declaration, delegate declaration, method declaration, local function
- Syntax: method invocation
- Span: method name
if (s.Contains("a"))
{
{
if (s.IndexOf("a", StringComparison.OrdinalIgnoreCase) != -1)
{
{
- Syntax: variable declaration, foreach statement
- Span: type
IEnumerable<object> items = new List<object>();
List<object> items = new List<object>();
- Syntax: method, constructor, property, indexer, operator, event, namespace, class, struct, interface
- Span: opening or closing brace
- Syntax: do statement, fixed statement, for statement, foreach statement, checked statement, if statement, lock statement, switch statement, try statement, unchecked statement, unsafe statement, using statement, while statement
- Span: opening or closing brace
- Syntax: return statement, yield return statement
- Span: selected statement, yield keyword or return keyword
- Syntax: ?: operator that is part of local declaration, assignment or (yield) return statement
string s = (x) ? "a" : "b";
string s;
if (x)
{
s = "a";
}
else
{
s = "b";
}
string s = (x) ? "a" : (y) ? "b" : "c";
string s;
if (x)
{
s = "a";
}
else if (y)
{
s = "b";
}
else
{
s = "c";
}
- Syntax: single-line comment
// comment
public class Foo
{
}
/// <summary>
/// comment
/// </summary>
public class Foo
{
}
- Syntax: do statement
- Span: do keyword
do
{
} while (condition);
while (condition)
{
}
- Syntax: foreach statement
foreach (object item in items)
{
yield return item;
}
for (int i = items.Count - 1; i >= 0; i--)
{
yield return items[i];
}
- Syntax: if statement
- Span: top if keyword or selected if statement
var ch = stringReader.Read();
if (ch == 10 || ch == 13)
{
return;
}
else
{
stringBuilder.Append(ch);
}
var ch = stringReader.Read();
switch (ch)
{
case 10:
case 13:
{
return;
}
default:
{
stringBuilder.Append(ch);
break;
}
}
- Syntax: interpolated string
string s = $"a{b}c";
string s = "a" + b + "c";
- Syntax: interpolated string
$"name: {name,0:f}, value: {value}"
string.Format("name: {0,0:f} value: {1}", name, value)
- Syntax: selected statements (first statement must be 'if' statement)
if (x)
return 1;
if (y)
{
return 2;
}
else if (z)
{
return 3;
}
return 0;
if (x)
{
return 1;
}
else if (y)
{
return 2;
}
else if (z)
{
return 3;
}
else
{
return 0;
}
- Syntax: while statement
- Span: while keyword
while (condition)
{
}
if (condition)
{
do
{
} while (condition);
}
- Syntax: method, constructor, property, indexer, operator, event, namespace, class, struct, interface
- Span: opening or closing brace
- Syntax: do statement, fixed statement, for statement, foreach statement, checked statement, if statement, lock statement, switch statement, try statement, unchecked statement, unsafe statement, using statement, while statement
- Span: opening or closing brace
- Syntax: switch section
- Span: close brace or empty line after switch section
switch (s)
{
case "a":
{
// ...
break;
}
default:
{
break;
}
}
switch (s)
{
case "a":
{
// ...
break;
}
case "a":
{
// ...
break;
}
default:
{
break;
}
}
- Syntax: lambda expression
void Foo()
{
x.Changed += (s, e) => Bar();
}
void Foo()
{
x.Changed += Changed;
}
void OnChanged(object sender, EventArgs e)
{
Bar();
}
- Syntax: if statement, while statement
- Span: condition
if (x && y) // Select 'y'
{
}
if(x)
{
if (y)
{
}
}
if (x || y) // Select 'y'
{
}
if(x)
{
}
if (y)
{
}
- Syntax: else clause, fixed statement, for statement, foreach statement, checked statement, if statement, lock statement, try statement, unsafe statement, using statement, while statement
- Syntax: class declaration, struct declaration, interface declaration, enum declaration, delegate declaration
- Span: identifier
- Syntax: type parameter constraint clause
private void Foo<T1, T2, T3>() where T1 : class where T2 : class where T3 : class
{
}
private void Foo<T1, T2, T3>()
where T1 : class
where T2 : class
where T3 : class
{
}
- Syntax: DebuggerDisplay attribute
[DebuggerDisplay("A: {A} B: {B}")]
public class Foo
{
public string A { get; }
public string B { get; }
}
DebuggerDisplay("{DebuggerDisplay,nq}")]
public class Foo
{
public string A { get; }
public string B { get; }
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string DebuggerDisplay
{
get { return $"A: {A} B: {B}"; }
}
}
- Syntax: class that implements IEnumerable<T>
- Span: identifier
using System;
using System.Collections;
using System.Collections.Generic;
class C<T> : IEnumerable<T>
{
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
using System;
using System.Collections;
using System.Collections.Generic;
class C<T> : IEnumerable<T>
{
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
public Enumerator GetEnumerator()
{
return new Enumerator(this);
}
public struct Enumerator
{
private readonly C<T> _c;
private int _index;
internal Enumerator(C<T> c)
{
_c = c;
_index = -1;
}
public T Current
{
get
{
throw new NotImplementedException();
}
}
public bool MoveNext()
{
throw new NotImplementedException();
}
public void Reset()
{
_index = -1;
throw new NotImplementedException();
}
public override bool Equals(object obj)
{
throw new NotSupportedException();
}
public override int GetHashCode()
{
throw new NotSupportedException();
}
}
//TODO: IEnumerable.GetEnumerator() and IEnumerable<T>.GetEnumerator() should return instance of EnumeratorImpl.
private class EnumeratorImpl : IEnumerator<T>
{
private Enumerator _e;
internal EnumeratorImpl(C<T> c)
{
_e = new Enumerator(c);
}
public T Current
{
get
{
return _e.Current;
}
}
object IEnumerator.Current
{
get
{
return _e.Current;
}
}
public bool MoveNext()
{
return _e.MoveNext();
}
void IEnumerator.Reset()
{
_e.Reset();
}
void IDisposable.Dispose()
{
}
}
}
- Syntax: field declaration
- Span: idenifier
public class Foo
{
private string _bar;
public Foo()
{
}
public Foo(object parameter)
{
}
public Foo(object parameter1, object parameter2)
: this(parameter1)
{
}
}
public class Foo
{
private string _bar;
public Foo(string bar)
{
_bar = bar;
}
public Foo(object parameter, string bar)
{
_bar = bar;
}
public Foo(object parameter1, object parameter2, string bar)
: this(parameter1, bar)
{
_bar = bar;
}
}
- Syntax: expression that has constant value
public const string Value = "x";
void Foo()
{
string x = Value;
}
public const string Value = "x";
void Foo()
{
string x = "x";
}
- Syntax: if statement
- Span: if keyword
if (condition1)
{
if (condition2)
{
Foo();
}
}
if (!condition1)
{
return;
}
if (!condition2)
{
return;
}
Foo();
if (!condition1)
{
return;
}
if (!condition2)
{
return;
}
Foo();
if (condition1)
{
if (condition2)
{
Foo();
}
}
- Syntax: System.Linq.Enumerable.Any(Func<T, bool>) or System.Linq.Enumerable.All(Func<T, bool>)
- Span: method name
if (items.Any(predicate)
{
}
if (items.All(!predicate)
{
}
if (items.All(predicate)
{
}
if (items.Any(!predicate)
{
}
- Syntax: prefix/postfix unary expression
- Span: operator token
int i = 0;
i++;
int i = 0;
i--;
int i = 0;
++i;
int i = 0;
--i;
- Syntax: selected if statements
bool condition1 = false;
bool condition2 = false;
if (condition1)
{
return false;
}
if (condition2)
{
return false;
}
return true;
bool condition1 = false;
bool condition2 = false;
if (condition1 || condition2)
{
return false;
}
return true;
- Syntax: if statement
- Span: if keyword
if (x)
{
if (y)
{
}
}
else
{
}
if (x && y)
{
}
else
{
}
- Syntax: unsafe declaration
- Span: unsafe modifier
public class Foo
{
public unsafe void Bar()
{
}
}
public unsafe class Foo
{
public void Bar()
{
}
}
- Syntax: property in class/struct that implements System.ComponentModel.INotifyPropertyChanged
- Span: setter
- Syntax: method declaration, local function, lambda, anonymous method
- Span: async keyword
class C
{
async Task<object> FooAsync()
{
return await BarAsync().ConfigureAwait(false);
}
}
class C
{
Task<object> FooAsync()
{
return BarAsync();
}
}
- Syntax: do statement, else clause, fixed statement, for statement, foreach statement, if statement, lock statement, using statement, while statement
- Span: block with a single statement
- Syntax: selected enum member(s)
public enum Foo
{
One = 1,
Two = 2,
Three = 3
}
public enum Foo
{
One,
Two,
Three
}
- Syntax: method, constructor, property, indexer, operator, event, namespace, class, struct, interface
- Span: opening or closing brace
- Syntax: do statement, fixed statement, for statement, foreach statement, checked statement, if statement, lock statement, switch statement, try statement, unchecked statement, unsafe statement, using statement, while statement
- Span: open/close brace
- Syntax: method group
Func<object, object, object> func = Foo;
Func<object, object, object> func = (f, g) => Foo(f, g)
- Syntax: object creation expression
var x = new object();
object x = null;
var arr = new object[0];
object[] arr = null;
- Syntax: selected case labels with string literal or enum field
bool Foo(string s)
{
switch (s)
{
case "d":
case "b":
case "a":
case "c":
return true;
default:
return false;
}
}
bool Foo(string s)
{
switch (s)
{
case "a":
case "b":
case "c":
case "d":
return true;
default:
return false;
}
}
- Syntax: namespace declarations, class declarations, struct declarations, interface declarations, enum declarations
- Span: selected member declarations
- Syntax: local variable declaration
- Span: equals token
var s = GetValue();
string s;
s = GetValue();
- Syntax: if statement that has logical or expression as a condition
- Span: top if keyword or selected if statement
- Syntax: if statement
- Span: selected if statement or topmost if keyword
if (condition1)
{
return Foo1();
{
else if (condition2)
{
return Foo2();
}
else
{
return false;
}
if (condition1)
{
return Foo1();
{
if (condition2)
{
return Foo2();
}
return false;
- Syntax: binary expression
- Span: binary operator
if (x && y)
{
{
if (y && x)
{
{
- Syntax: multi-line comment
/*string s = null;*/
string s = null;
- Syntax: collection initializer
var dic = new Dictionary<int, string>() { { 0, "0" } };
var dic = new Dictionary<int, string>() { [0] = "0" };
- Syntax: foreach statement
- Span: foreach keyword
foreach (var item in items)
{
yield return item;
}
using (var en = items.GetEnumerator())
{
while (en.MoveNext())
{
yield return item;
}
}
(Generated with DotMarkdown)