Skip to content

Instantly share code, notes, and snippets.

var tree = CSharpSyntaxTree.ParseText(@"
public class MyClass {
int Method1() { return 0; }
void Method2()
{
int x = Method1();
}
}
}");
class MyClass
{
#region MyRegion
#endregion
}
var tree = CSharpSyntaxTree.ParseText(@"
public class MyClass{
#region MyRegion
#endregion
}");
//Try finding them as nodes.
var regionNodes = tree.GetRoot().DescendantNodes().OfType<RegionDirectiveTriviaSyntax>();
//Try finding them as trivia?
var regionTrivia = tree.GetRoot().DescendantTrivia().OfType<RegionDirectiveTriviaSyntax>();
var tree = CSharpSyntaxTree.ParseText(@"
public class MyClass{
#region MyRegion
#endregion
}");
//Descend into all node children
//Descend into all trivia children
var regionNodes = tree.GetRoot().DescendantNodes(descendIntoChildren: null, descendIntoTrivia true).OfType<RegionDirectiveTriviaSyntax>();
var tree = CSharpSyntaxTree.ParseText(@"
public class MyClass{
#region MyRegion
#endregion
}");
//Descend into all node children
//Descend into all trivia children
var regionNodes = tree.GetRoot().DescendantNodes(descendIntoChildren: null, descendIntoTrivia: true).OfType<RegionDirectiveTriviaSyntax>();
class MyClass
{
#region MyRegion
#endregion
}
var outWindow = GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
var debugPaneGuid = VSConstants.GUID_OutWindowGeneralPane;
IVsOutputWindowPane pane;
outWindow.GetPane(ref debugPaneGuid, out pane);
IVsTextView view = pane as IVsTextView;
class MyClass
{
int myField = 0;
public int MyProperty {get; set;}
public void MyMethod() { }
}
class MyClass
{
int myField = 0;
public int MyProperty {get; set;}
public void MyMethod() { }
}
class MyClass
{
int myField = 0;
public int MyProperty {get; set;}
public void MyMethod() { }
}