Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Roslyn完成API获取函数参数_C#_.net_Vb.net_Roslyn_Roslyn Code Analysis - Fatal编程技术网

C# 从Roslyn完成API获取函数参数

C# 从Roslyn完成API获取函数参数,c#,.net,vb.net,roslyn,roslyn-code-analysis,C#,.net,Vb.net,Roslyn,Roslyn Code Analysis,我试图使用完成API来构建自动完成功能。结果是正确的,但我无法获得方法签名。 例如:如果我键入“string.”,API将返回所有方法,如“Format”,“Compare”,但在“string.Format”(之后,它不会返回所有可能的方法签名,如Format(string,Object),Format(string,Object[])等。有人能帮我实现这一目标吗 var expression = "String."; var code = String.Format(CultureInfo.

我试图使用完成API来构建自动完成功能。结果是正确的,但我无法获得方法签名。 例如:如果我键入“string.”,API将返回所有方法,如“Format”“Compare”,但在“string.Format”(之后,它不会返回所有可能的方法签名,如Format(string,Object),Format(string,Object[])等。有人能帮我实现这一目标吗

var expression = "String.";
var code = String.Format(CultureInfo.InvariantCulture,
                           @"
                               Imports System

                               Sub Main(args As String[])
                                     Dim typeUnderInvestigation As String = {0}
                                End sub
                             ", expression);

var projectInfo = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "MyProject", "MyProject", LanguageNames.VisualBasic)
                             .WithMetadataReferences(new[] 
                             {
                                  MetadataReference.CreateFromFile(typeof(object).Assembly.Location)
                             });

var project = workspace.AddProject(projectInfo);
var document = workspace.AddDocument(project.Id, "MyFile.cs", SourceText.From(code));

// position is the last occurrence of "Guid." in our test code
// in real life scenarios the editor surface should inform us
// about the current cursor position
var position = code.LastIndexOf(expression, StringComparison.InvariantCulture) + expression.Length;

var completionService = CompletionService.GetService(document);
var results = await completionService.GetCompletionsAsync(document, position);