Is there anyway to connect a piece of code to its "using" statement using the Roslyn framework?
For example, given this piece of code:
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Serilog;
using System.Collections.Generic;
namespace CodeAnalyzer.Service.CodeAnalysis.CSharp
{
public static class CSharpCodeAnalyser
{
/// <summary>
/// Retrieves all of the using statements from a code page
/// </summary>
/// <param name="codeDocument"></param>
/// <param name="logger"></param>
/// <returns></returns>
public static List<string> IdentifyUsings(string codeDocument, ILogger logger)
{
var usingList = new List<string>();
try
{
SyntaxTree tree = CSharpSyntaxTree.ParseText(codeDocument);
CompilationUnitSyntax root = tree.GetCompilationUnitRoot();
foreach (var item in root.Usings)
{
usingList.Add(item.Name.ToString());
}
}
catch (System.Exception ex)
{
logger.Error(ex, ex.Message);
throw;
}
return usingList;
}
} }
Could I know what assembly "CSharpSyntaxTree" belongs to?