Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Roslyn does provide code completion services through the <code>ICompletionService</code> and <code>ICompletionProvider</code> interfaces, but they seem to mostly be internal and meant to be accessed when hosted within Visual Studio. However, it is possible to get a hold of the C# code completion types using a couple of reflection hacks, as illustrated by the <a href="https://github.com/khellang/scriptcs-editor/tree/master/ScriptCsPad" rel="nofollow noreferrer" title="ScriptCS Pad @ GitHub">ScriptCS Pad</a> project. If you can get this to work, I expect you should get VS-grade code completion.</p> <p>Alternatively, you can do it "by hand", using the public APIs provided by Roslyn. I am not well-versed in them, but the following should get you started in listing the members of the expression to the left of the member access dot. Note that it ignores extension methods and visibility rules, does no error handling and is probably flawed in many other ways. Doing this reliably probably doesn't qualify as "simple" code completion, though.</p> <pre><code>var code = @" using System; public class Test { public void TestMethod() { var now = DateTime.Now; now. } }"; Console.WriteLine(code); var syntaxTree = CSharpSyntaxTree.ParseText(code); var compilation = CSharpCompilation.Create("foo") .AddReferences(MetadataReference.CreateAssemblyReference(typeof(DateTime).Assembly.FullName)) .AddSyntaxTrees(syntaxTree); var semanticModel = compilation.GetSemanticModel(syntaxTree); var dotTextSpan = new TextSpan(code.IndexOf("now.") + 3, 1); var memberAccessNode = (MemberAccessExpressionSyntax)syntaxTree.GetRoot().DescendantNodes(dotTextSpan).Last(); var lhsType = semanticModel.GetTypeInfo(memberAccessNode.Expression).Type; foreach (var symbol in lhsType.GetMembers()) { if (!symbol.CanBeReferencedByName || symbol.DeclaredAccessibility != Accessibility.Public || symbol.IsStatic) continue; Console.WriteLine(symbol.Name); } </code></pre> <p><strong>EDIT</strong>: Note that this answer was probably made obsolete by the new Roslyn bits.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload