roslyn

What is the experimental feature “indexed members”?

喜欢而已 提交于 2019-12-22 01:59:00
问题 On the new Roslyn Preview site it mentions being able to try out potential language features, and lists three such features. The first two I've heard of before (for example here), but I can't figure out from the code sample what "indexed members" are. Can anyone explain what these are, either based on another source or the code sample? (It's worth nothing $x is not a valid identifier in C# 5.) UPDATE - According to the Roslyn Feature Status page, this feature has been withdrawn. 回答1: .$foobar

How do I get a IMethodSymbol or the syntax node of the method declaration from a InvocationExpressionSyntax node which calls the method?

孤街浪徒 提交于 2019-12-22 00:28:12
问题 In the implementation of my analyzer I am in the AnalyzeSymbol method: public override void Initialize(AnalysisContext context) { context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.Method); } private static void AnalyzeSymbol(SymbolAnalysisContext context) { // here I look through the syntax of the method body in order to find invocations. var methodSymbol = context.Symbol as IMethodSymbol; var location = methodSymbol.Locations.FirstOrDefault(); var methodNode = location.SourceTree

Roslyn SyntaxTree changes injection

本秂侑毒 提交于 2019-12-21 18:33:15
问题 I wrote my class MonitorSyntaxRewriter, which inherits from CSharpSyntaxRewriter. With this class I change my SyntaxTree. But, how can I "inject" this modified synaxtree somewhere? I mean, I have some random project in Visual Studio, and on Build, I would like all the syntax trees go through this MonitorSyntaxRewriter. Is there some option for that? Or is there some other possible workaround? (creating new solution...). I just don't want my *.cs files being changed in the project. 回答1: As far

Roslyn: get the symbol for a type defined in a third-party library

扶醉桌前 提交于 2019-12-21 17:31:57
问题 using Roslyn/Microsoft.CodeAnalysis, how can I get the ISymbol for a third-party type, ie, a type defined in a referenced assembly which is not part of the solution? In my particular case, I'm looking for JSON.NET's JObject, but actually the same question would be valid for BCL stuff like StringBuilder etc. The only idea I've come up so far is to implement a CSharpSyntaxWalker which looks for all method invocations, property accesses and constructor calls, checks whether they are made on the

Roslyn add new method to an existing class

这一生的挚爱 提交于 2019-12-21 17:02:15
问题 I'm investigating the use of the Roslyn compiler within a Visual Studio Extension (VSIX) that uses the VisualStudioWorkspace to update existing code. Having spent the last few days reading up on this, there seem to be several ways to achieve this....I'm just not sure which is the best approach for me. Okay, so let's assume that the User has their solution open in Visual Studio 2015. They click on my Extension and (via a form) they tell me that they want to add the following method definition

Can Roslyn be used to generate dynamic method similar to DynamicMethod IL generation

断了今生、忘了曾经 提交于 2019-12-21 12:30:57
问题 I have been using DynamiMethod to generate the IL using method.GetILGenerator(); This works well but is of course very hard to use since you generally don't want to work with low level IL in a high level language like C#. Now since there is Roslyn I though I can use that instead. I have tried to figure out how to use Roslyn to do similar thing: generate a dynamic method and then create a delegate for it. The only way I was able to do that is to have full class like this SyntaxTree syntaxTree

Get TypeSyntax from ITypeSymbol

假如想象 提交于 2019-12-21 07:49:06
问题 I'm experimenting a bit with the Roslyn-CTP. Currently I'm trying to replace var with the concrete type. var i=1; should become: int i=1; Figuring out the inferred type is easy. But since this part happens in the semantic model I get a ITypeSymbol . The replacement happens in the syntax model, so I need a TypeSyntax . Since I don't want a bloated name ( global::System.Int32 ), the conversion is context dependent ( using , nested types etc.). The Visual studio version that's part of Roslyn

How to turn off Roslyn Code Fixes in VS 2015?

蹲街弑〆低调 提交于 2019-12-21 03:49:45
问题 How can I turn off Roslyn Code Fixes in VS 2015? It works correctly (with the latest Resharper 9.1.2), but still while it initializes it blocks navigation, I mean Home, End, Left, Right are delayed for 0.5 - 1.5 seconds. Also it seems to be fool the nav keys, now it's the dozenth times I find myself in the VS main menu, or an other source file just by pressing the 4 nav keys I've listed, I don't know how... What I've tried so far: Look for in the Tools/Options and search for 'Roslyn' Context

What is new .Net Native [closed]

橙三吉。 提交于 2019-12-21 03:12:16
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Today I have read an article about the new .Net Native on MSDN. "Windows Store apps start up to 60% faster with .NET Native and have a much smaller memory footprint. Our first release is a Developer Preview that allows you to develop and test apps with this new compiler. This

Using the open source released “roslyn” to read code file and generate new code files

℡╲_俬逩灬. 提交于 2019-12-20 13:57:13
问题 Where do I start? in my current solution I have models like this: public class MyAwesomeModel { .... } I want to take the roslyn code project to parse the source files and go over the syntax trees to generate new code files. Take those source files and add them to a c# project file to import in my solution again in visual studio. Where do I start. Cloning roslyn and just write a console app that reference all of roslyn and start digging into roslyn to find out how, or is there any blogs