Created
July 23, 2014 20:18
-
-
Save natemcmaster/b44d8b0ef2dd4d363036 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Microsoft.CodeAnalysis; | |
using Microsoft.CodeAnalysis.CSharp; | |
using Microsoft.CodeAnalysis.CSharp.Syntax; | |
using Microsoft.CodeAnalysis.Host; | |
using Microsoft.CodeAnalysis.Host.Mef; | |
using Microsoft.CodeAnalysis.Recommendations; | |
namespace ConsoleApplication2 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var workspace = new CustomWorkspace(); | |
var proj = workspace.AddProject("Program", LanguageNames.CSharp); | |
var documentText = @" | |
using System; | |
namespace Test{ | |
class Program{ | |
static void Main(string[] args) | |
{ | |
var name = ""hwllo eorld""; | |
} | |
} | |
} | |
"; | |
var doc = workspace.AddDocument(proj, "Program.cs", documentText); | |
SyntaxTree tree = CSharpSyntaxTree.ParseText(documentText); | |
var root = (CompilationUnitSyntax)tree.GetRoot(); | |
var compilation = CSharpCompilation.Create("HelloWorld") | |
.AddReferences( | |
new MetadataFileReference( | |
typeof(object).Assembly.Location)) | |
.AddSyntaxTrees(tree); | |
var model = compilation.GetSemanticModel(tree); | |
var rec =Recommender.GetRecommendedSymbolsAtPosition(model, documentText.IndexOf("eorld")+8, workspace); | |
foreach (var symbol in rec) | |
{ | |
var parts = symbol.ToMinimalDisplayParts(model, documentText.IndexOf("eorld") + 8); | |
Console.WriteLine(); | |
} | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment