Here are the examples of the csharp api class APISampleUnitTestsCS.FAQ.MyAnnotation.GetPosition(Microsoft.CodeAnalysis.SyntaxAnnotation) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
0
1. Example
Project: roslyn
Source File: FAQ.cs
Source File: FAQ.cs
[FAQ(25)] [Fact] public void UseSyntaxAnnotations() { var tree = SyntaxFactory.ParseSyntaxTree(@" using System; class Program { static void Main() { int i = 0; Console.WriteLine(i); } }"); // Tag all tokens that contain the letter 'i'. var rewriter = new MyAnnotator(); SyntaxNode oldRoot = tree.GetRoot(); SyntaxNode newRoot = rewriter.Visit(oldRoot); Assert.False(oldRoot.ContainsAnnotations); Assert.True(newRoot.ContainsAnnotations); // Find all tokens that were tagged with annotations of type MyAnnotation. IEnumerable<SyntaxNodeOrToken> annotatedTokens = newRoot.GetAnnotatedNodesAndTokens(MyAnnotation.Kind); var results = string.Join("\r\n", annotatedTokens.Select(nodeOrToken => { Assert.True(nodeOrToken.IsToken); var annotation = nodeOrToken.GetAnnotations(MyAnnotation.Kind).Single(); return string.Format("{0} (position {1})", nodeOrToken.ToString(), MyAnnotation.GetPosition(annotation)); })); Assert.Equal(@"using (position 2) static (position 4) void (position 2) Main (position 2) int (position 0) i (position 0) WriteLine (position 2) i (position 0)", results); }
0
2. Example
Project: roslyn
Source File: FAQ.cs
Source File: FAQ.cs
[FAQ(25)] [TestMethod] public void UseSyntaxAnnotations() { var tree = SyntaxFactory.ParseSyntaxTree(@" using System; class Program { static void Main() { int i = 0; Console.WriteLine(i); } }"); // Tag all tokens that contain the letter 'i'. var rewriter = new MyAnnotator(); SyntaxNode oldRoot = tree.GetRoot(); SyntaxNode newRoot = rewriter.Visit(oldRoot); Assert.IsFalse(oldRoot.ContainsAnnotations); Assert.IsTrue(newRoot.ContainsAnnotations); // Find all tokens that were tagged with annotations of type MyAnnotation. IEnumerable<SyntaxNodeOrToken> annotatedTokens = newRoot.GetAnnotatedNodesAndTokens(MyAnnotation.Kind); var results = string.Join("\r\n", annotatedTokens.Select(nodeOrToken => { Assert.IsTrue(nodeOrToken.IsToken); var annotation = nodeOrToken.GetAnnotations(MyAnnotation.Kind).Single(); return string.Format("{0} (position {1})", nodeOrToken.ToString(), MyAnnotation.GetPosition(annotation)); })); Assert.AreEqual(@"using (position 2) static (position 4) void (position 2) Main (position 2) int (position 0) i (position 0) WriteLine (position 2) i (position 0)", results); }