roslyn

Using Roslyn to parse/transform/generate code: am I aiming too high, or too low?

萝らか妹 提交于 2019-12-29 18:42:02
问题 (What I'm trying to do is work around the Application.Settings/MVVM problem by generating an interface and wrapper class from the vs-generated settings file.) What I'd like to do is: Parse a class declaration from file Generate an interface declaration based on just the (non static) properties of the class Generate a wrapper class which implements this interface, takes an instance of the original class in the constructor, and 'pipes' all the properties through to the instance. Generate

Using Roslyn to parse/transform/generate code: am I aiming too high, or too low?

谁说胖子不能爱 提交于 2019-12-29 18:40:34
问题 (What I'm trying to do is work around the Application.Settings/MVVM problem by generating an interface and wrapper class from the vs-generated settings file.) What I'd like to do is: Parse a class declaration from file Generate an interface declaration based on just the (non static) properties of the class Generate a wrapper class which implements this interface, takes an instance of the original class in the constructor, and 'pipes' all the properties through to the instance. Generate

Why are async state machines classes (and not structs) in Roslyn?

天大地大妈咪最大 提交于 2019-12-29 11:43:53
问题 Let’s consider this very simple async method: static async Task myMethodAsync() { await Task.Delay(500); } When I compile this with VS2013 (pre Roslyn compiler) the generated state-machine is a struct. private struct <myMethodAsync>d__0 : IAsyncStateMachine { ... void IAsyncStateMachine.MoveNext() { ... } } When I compile it with VS2015 (Roslyn) the generated code is this: private sealed class <myMethodAsync>d__1 : IAsyncStateMachine { ... void IAsyncStateMachine.MoveNext() { ... } } As you

Why are async state machines classes (and not structs) in Roslyn?

為{幸葍}努か 提交于 2019-12-29 11:42:21
问题 Let’s consider this very simple async method: static async Task myMethodAsync() { await Task.Delay(500); } When I compile this with VS2013 (pre Roslyn compiler) the generated state-machine is a struct. private struct <myMethodAsync>d__0 : IAsyncStateMachine { ... void IAsyncStateMachine.MoveNext() { ... } } When I compile it with VS2015 (Roslyn) the generated code is this: private sealed class <myMethodAsync>d__1 : IAsyncStateMachine { ... void IAsyncStateMachine.MoveNext() { ... } } As you

Compiler Issue in Visual Basic Project With Microsoft.CodeAnalysis.Emit

大兔子大兔子 提交于 2019-12-25 19:04:27
问题 I have developed following code to generate dll files using Microsoft.CodeAnalysis.Emit library. The code successfully generates dll files for C# projects. However it doesn't successfully build Visual Basic projects. It throws lot of compiler errors for VB projects which build successfully using the VS IDE. Please see the errors thrown for a basic Windows application project. Is there any specific compiler options for VB projects? Please advice how to resolve this. Microsoft.CodeAnalysis

Roslyn Find Same Node in Changed Document

一个人想着一个人 提交于 2019-12-25 10:19:45
问题 As we all know Roslyn Syntax Trees are Immutable, so after making changes you need to get a new node. I'm trying to update a document using the document editor, but I keep getting an error that the node is not found in the syntax tree. public static T FindEquivalentNode<T>(this Document newDocument, T node) where T : CSharpSyntaxNode { var root = newDocument.GetSyntaxRootAsync().Result; return root.DescendantNodes().OfType<T>() .FirstOrDefault(newNode => SyntaxFactory.AreEquivalent(newNode,

Automatic interpolated strings

放肆的年华 提交于 2019-12-25 09:48:42
问题 I have used interpolated strings (ie $"Hello my name is {name}" ) for a while and I use this much more heavily than ordinary strings. Is there a way to tell the compiler that to always assume that a string is interpolated so I don't have to type the dollar sign? Using event variable, a #pragma, something in .sln, or a nuget package? 来源: https://stackoverflow.com/questions/44166762/automatic-interpolated-strings

Automatic interpolated strings

老子叫甜甜 提交于 2019-12-25 09:48:06
问题 I have used interpolated strings (ie $"Hello my name is {name}" ) for a while and I use this much more heavily than ordinary strings. Is there a way to tell the compiler that to always assume that a string is interpolated so I don't have to type the dollar sign? Using event variable, a #pragma, something in .sln, or a nuget package? 来源: https://stackoverflow.com/questions/44166762/automatic-interpolated-strings

What is the canonical way to convert a MethodDeclarationSyntax to a ConstructorDeclarationSyntax?

为君一笑 提交于 2019-12-25 04:23:00
问题 I'm writing an analyzer and codefix for an API migration (AutoMapper V5 Profiles), converting a protected override Configure method to a constructor: from: public class MappingProfile : Profile { protected override Configure() { CreateMap<Foo, Bar>(); RecognizePrefix("m_"); } } to public class MappingProfile : Profile { public MappingProfile() { CreateMap<Foo, Bar>(); RecognizePrefix("m_"); } } I've found a way to convert the method node into a constructor, but I've been struggling a lot to

Not finding all of the symbols I need,How to find more symbols using the Roslyn API

▼魔方 西西 提交于 2019-12-24 13:16:20
问题 I am using the roslyn API and ace text editor to create a web IDE. When i hover over data i need it to find the symbol at the given location. This works in some situations by calling the roslyn method: var symbol = SymbolFinder.FindSymbolAtPosition(semanticModel, offset, dotNetCodeManager.Solution.Workspace, cancellationToken); An example of the situations where this works is when i hover my mouse over the word "table" in the below example. var SchemaName = table.Schema.Name; However when i