roslyn

Built-in C#/VB.Net editor with intellisense - Roslyn, VSTA, or something else?

江枫思渺然 提交于 2019-12-07 00:19:49
问题 I need to provide scripting capabilities within my application, allowing customers to extend its functionality using our object model. I was hoping to offer some kind of integrated C#/VB.Net editor with intellisense, but after looking at products like AvalonEdit and ScintillaNet, they don't appear to provide true code-completion, just an API where you can provide your own list of items to appear in the popup autocomplete list. I was therefore wondering if Roslyn provided any such features?

Change files using Roslyn

岁酱吖の 提交于 2019-12-06 21:56:27
I'm trying to write a command line tool that modifies some code using Roslyn. Everything seems to go well: the solution is opened, the solution is changed, the Workspace.TryApplyChanges method returns true. However no actual files are changed on disk. What's up? Below is the top level code I'm using. static void Main(string[] args) { var solutionPath = args[0]; UpdateAnnotations(solutionPath).Wait(); } static async Task<bool> UpdateAnnotations(string solutionPath) { using (var workspace = MSBuildWorkspace.Create()) { var solution = await workspace.OpenSolutionAsync(solutionPath); var

Code Formatting in Roslyn SDK Preview

左心房为你撑大大i 提交于 2019-12-06 20:26:14
问题 In an earlier version (Roslyn CTP), I was using following code to format my generated code and it was working perfectly fine: SyntaxNode.Format(FormattingOptions.GetDefaultOptions()).GetFormattedRoot() With the new Roslyn version it no longer does, so what is the equivalent for the above code in the new version (SDK Preview)? 回答1: You can format SyntaxNodes using the Microsoft.CodeAnalysis.Formatting.Formatter like this (if you have a workspace): using Microsoft.CodeAnalysis.Formatting; var

Roslyn API documentation [closed]

断了今生、忘了曾经 提交于 2019-12-06 19:13:59
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I've developing with the Roslyn CTP, and I'm using the walkthroughs on MSDN and other code samples people have posted to learn. However, I can't find any documentation that explains the various classes and methods that are part of the API. I understand that the API is still in development, but is there a source

How is C# string interpolation compiled?

你。 提交于 2019-12-06 18:30:06
问题 I know that interpolation is syntactic sugar for string.Format() , but does it have any special behavior/recognition of when it is being used with a string formatting method? If I have a method: void Print(string format, params object[] parameters) And the following call to it using interpolation: Print($"{foo} {bar}"); Which of the following calls lines is most equivalent to the compiled result of string interpolation? Print(string.Format("{0} {1}", new[] { foo, bar })); Print("{0} {1}", new

What's the right way to update Roslyn's Document while typing?

时光毁灭记忆、已成空白 提交于 2019-12-06 13:21:03
What's the right way to update Roslyn's Document when user is typing new text? Should I call SourceText.WithChanges and then Document.WithText on each char, or is there a more efficient way? Unfortunately throttling is not an answer, see my question What's the most efficient way to use Roslyn's CompletionSevice when typing? where an API implies that SourceText / Document must be up to date on each char. Doing SourceText.WithChanges on each character is probably your best bet, assuming there's not a more efficient way you can create your own derived type of SourceText like we do in Visual

C# Roslyn change type of comment

流过昼夜 提交于 2019-12-06 11:28:50
问题 I'm trying to make an extension for Visual Studio that changes some syntax in the code. Actually, I've done the first step which was to change the name of a variable if this name was not okey with the rules we use in the firm. For example: int newVariable; double test; will be changed into: int iNewVariable; double dblTest; Now I have to change this type of comment: (SingleLineComment) //this is a single line Comment Into a MultiLineComment /*Here it's a MultiLine one*/ I use the Roslyn

VSTS Build fails/Publish fails to find roslyn\csc.exe in the bin folder

帅比萌擦擦* 提交于 2019-12-06 11:10:46
问题 We have a website project which has the following nuget packages installed Microsoft.CodeDom.Providers.DotNetCompilerPlatform - 1.0.8 Microsoft.Net.Compilers - 2.4.0 The web.config has the following <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4"

How do I get a Roslyn workspace from a VS package?

怎甘沉沦 提交于 2019-12-06 07:27:44
From a Visual Studio 2015 CTP5 package, how do I get the current Roslyn workspace? I looked at How to get reference to 'Roslyn' Workspace object from IVsSolution? and Roslyn: How to get a reference to Workspace from currently loaded solution? but I still can't make it work: Workspace.CurrentWorkspace does not exist anymore I have tried importing the VisualStudioWorkspace but it is still null: public sealed class VSPackage1Package : Package { .... [Import] public VisualStudioWorkspace Workspace { get; set; } .... protected override void Initialize() { // Workspace is null here... Is there a

How to remove a list of SyntaxNode from the Document using Roslyn code fix provider APIs?

浪子不回头ぞ 提交于 2019-12-06 06:24:45
I'm having a custom generated variable declaration using SyntaxFactory.VariableDeclaration and a list of SyntaxNode 's collected according to some conditions. I did the following: Modify the node var newRoot = root.ReplaceNode(expression, newVariableDeclaration) This successfully modified the node with the newVariableDeclaration . In a loop remove the nodes corresponding to the ones present in the list foreach (var listObject in listObjects) { newRoot = newRoot.RemoveNode(listObject, SyntaxRemoveOptions.KeepNoTrivia); } This doesn't change the newRoot and all the listObject required to be