roslyn

How to execute script with xamarin forms on android

不羁岁月 提交于 2019-12-10 18:22:31
问题 I'm trying to run a C # script using Xamarin Forms on Android Mono. When I run the script I get the error: System.IO.FileNotFoundException: Could not find file "/mscorlib.dll" Here is the code I am trying to execute: object result; var script = CSharpScript.Create("DateTime.Today.Year",ScriptOptions.Default.WithImports("System")); script.RunAsync().ContinueWith(s => result = s.Result).Wait(); 来源: https://stackoverflow.com/questions/51212599/how-to-execute-script-with-xamarin-forms-on-android

Attach VsPackage to Roslyn Instance

两盒软妹~` 提交于 2019-12-10 18:09:30
问题 I'm trying to create a VsPackage that makes use of the Roslyn Language Services. Under the properties of my VsPackage, I've changed the command line arguments to: /rootsuffix Roslyn When running the project, the instance of Visual Studio that starts up is correctly using Roslyn. (I see [Roslyn] next to the names of .cs files I have open). However, my VsPackage is not deployed to this instance of Visual Studio. I have opened up the SyntaxVisualizerExtension VsPackage that ships with Roslyn and

How can we easily find what line in the code causes a runtime exception?

♀尐吖头ヾ 提交于 2019-12-10 17:39:00
问题 Consider the following analyzer: public void AnalyzeNode(SyntaxNode node, SemanticModel semanticModel, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken) { var throwStatement = node as ThrowStatementSyntax; var isObjectCreationExpression = throwStatement.Expression is ObjectCreationExpressionSyntax; var obj = throwStatement.Expression as ObjectCreationExpressionSyntax; var isCorrectTypeOfExpression = (obj.Type as IdentifierNameSyntax).Identifier.Text == typeof

Outdenting of content of removed block

假如想象 提交于 2019-12-10 16:15:14
问题 I'm writing a Roslyn Diagnostic with Code Fix. If there's a try block with one empty catch block, i want to provide the option to remove the catch block and replace the try block with its content. My problem is the outdenting of the content of the try block. I tried using the Formatter, but the lines are still indentend one level too much. Here's my code: private async Task<Document> RemoveTryCatchBlockAsync(Document document, TryStatementSyntax tryBlock, CancellationToken cancellationToken)

How stable is the Roslyn CTP as a replacement for dummy console apps?

限于喜欢 提交于 2019-12-10 15:44:27
问题 I frequently find myself making a dummy console app to test something simple out. (For example how does DateTime.Parse like a YYYY-MM-DD-HH-MM-SS formatted string?) I know that Roslyn has the C# interactive window to allow such simple tests to be run in the IDE with my solution still open. This is the only feature I am really wanting. But how stable is Roslyn CTP? Is it going to mess up my IDE? Slow me down when I am not using it? Is it only used for the Roslyn features? Or is it going to try

How do I replace a string variable with a var in Roslyn?

柔情痞子 提交于 2019-12-10 14:33:59
问题 For local declarations like: string a = string.Empty; How can I write a diagnostic to change it to: var a = string.Empty; 回答1: I've put together a code fix with diagnostic. Here's the interesting parts: Implementation of AnalyzeNode from ISyntaxNodeAnalyzer public void AnalyzeNode(SyntaxNode node, SemanticModel semanticModel, Action<Diagnostic> public void AnalyzeNode(SyntaxNode node, SemanticModel semanticModel, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken) { var

extending c# syntax with roslyn

♀尐吖头ヾ 提交于 2019-12-10 14:12:18
问题 I'm trying to implement a "return if"/"return value if" without an else case, since I only want to return or return a value if a condition is valid. I know, there is the if (condition) return; or if (condition) return value; but I want to have the code a bit cleaner AND it would be nice to have that syntax since it is more readable. I heard with roslyn this is possible and read the question with its answeres here: Is there a way to implement custom language features in C#? but I have no clue

What Replaces Code Analysis in Visual Studio 2019?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 12:50:29
问题 I'm toying with getting our team and projects ready for VS 2019. Right away, trying to set up Code Analysis for a new project, I find this: So, if this is deprecated (and apparently can't even be used, so I'm thinking "deprecated" really means "gone"), where are we supposed to set up our Rule Sets? Is there some other location, or perhaps an altogether new solution to the problem of style and code quality? 回答1: Going forward, static analysis will be provided by Roslyn analyzers: https:/

Go to definition from text position with roslyn

早过忘川 提交于 2019-12-10 12:13:45
问题 How to get file name and position of definition of any symbol under the current custom position and file (within project or solution)? I do the following steps (simplified explanation): Create collection of syntax trees and compilation by the following way: SyntaxTrees = new List<SyntaxTree>(); foreach (var file in projectFiles) syntaxTrees.Add(SyntaxTree.ParseText(File.ReadAllText(file)); Compilation = Compilation.Create("temp.cs", null, SyntaxTrees, new MetadataReference[] { mscorlib });

Create a method call analyzer with Roslyn

纵饮孤独 提交于 2019-12-10 11:53:13
问题 I need to parse a .cs file to look for a particular method. For instance, once the method named "X" is called, the analyzer should detect it. How can detect that this particular node is a method? Thanks in advance! 回答1: If you have a syntax node and semantic model for it you can try this: // node – is your current syntax node // semanticalModel – is your semantical model ISymbol symbol = semanticModel.GetSymbolInfo(node).Symbol ?? semanticModel.GetDeclaredSymbol(node); if(symbol.Kind ==