roslyn

How do I create a new root by adding and removing nodes retrieved from the old root?

大城市里の小女人 提交于 2019-11-28 07:40:52
I am creating a Code Fix that changes this: if(obj is MyClass) { var castedObj = obj as MyClass; } into this: var castedObj = obj as MyClass; if(castedObj != null) { } This means I have to do 3 things: Change the condition in the if statement. Move the casting right above the if statement. Remove the statement in the body. So far, all my attempts have stranded me at getting at most 2 of these things to work. I believe this problem occurs because you basically have 2 syntax nodes on the same level. As such, making a change to one of them invalidates the location of the other one. Or something

Roslyn and .NET Runtime version [duplicate]

自古美人都是妖i 提交于 2019-11-28 02:32:11
问题 This question already has answers here : Does C# 6.0 work for .NET 4.0? (5 answers) Closed 3 years ago . Is it possible to use Roslyn compiler and new features of C# 6.0 with old versions of .NET Runtime (for example, .NET 4.0)? For example, I want use the expression-bodied members ( int S => x + y; instead of int S { get { return x + y; } } ) in .NET 4.0 application. 回答1: The new C# 6.0 features don't depend upon framework support so yes, you an app compiled with the C# 6.0 compiler will run

Get Roslyn SyntaxToken from Visual Studio Text Selection (caret position)

久未见 提交于 2019-11-28 01:14:52
问题 I am attempting to bridge between the VSSDK and Roslyn SDK in a Visual Studio extension package and have been having a hard time with this. The ActivePoint.AbsoluteCharOffset given from Visual Studio does not match the element I get from Roslyn when using FindToken(offset). I'm fairly sure this has to do with how each side counts EOL characters based on my current working hack but I'm not 100% that my hack is going to hold up in the long run. My hack is this line: charOffset += point.Line; I

Roslyn: workspace loads in console application but not in msbuild task

若如初见. 提交于 2019-11-28 00:11:32
I have a custom msbuild task with this command: var workspace = Workspace.LoadStandAloneProject(csprojPath); When I run it, it throws the following error: System.InvalidCastException was unhandled by user code Message=Unable to cast transparent proxy to type 'Roslyn.Utilities.SerializableDataStorage'. Source=Roslyn.Services StackTrace: at Roslyn.Utilities.RemoteServices.CreateInstance[T]() at Roslyn.Services.Host.TemporaryStorageServiceFactory.CreateService(IWorkspaceServiceProvider workspaceServices) at Roslyn.Services.Host.WorkspaceServiceProviderFactory.Provider.c__DisplayClass7.b__4() at

How to suppress code analysis messages for all type members?

删除回忆录丶 提交于 2019-11-27 23:38:28
Let's say I have an enumeration of all currencies: public enum CurrencyType { /// <summary> /// United Arab Emirates dirham /// </summary> [EnumMember] AED = 784, /// <summary> /// Afghan afghani /// </summary> [EnumMember] AFN = 971, /// <summary> /// Albanian lek /// </summary> [EnumMember] ALL = 008, ... } VS 2015 code analysis keeps complaining about 100 violations of CA1709 for every individual member. This is an useful rule by itself, and I do not want to disable it; yet it is of not much help in this specific case, as CurrencyType is public and is used in a whole lot of other projects.

Using Roslyn Emit method with a ModuleBuilder instead of a MemoryStream

隐身守侯 提交于 2019-11-27 23:27:27
问题 I was having trouble with performance when using Roslyn to compile to a dynamic assembly. Compilation was taking ~3 seconds, compared to ~300 milliseconds to compile the same code when using the CodeDom compiler. Here's a pared-down version of the code I'm using to do the compilation: var compilation = CSharpCompilation.Create( "UserPayRules.dll", syntaxTrees, assembliesToAdd); using (var stream = new MemoryStream()) { stopWatch.Start(); var result = compilation.Emit(stream); stopWatch.Stop()

How to run Roslyn instead csc.exe from command line?

放肆的年华 提交于 2019-11-27 22:49:10
After installing VS 2015, running csc.exe from command line causes this message to be displayed to console: This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240 The link redirects to Roslyn's repository at GitHub. So, is the a way to run "compilers that support newer versions" (Roslyn) from command line? It sounds like your path is inappropriate, basically. If you open

what is the state of the “C# compiler as a service ” [closed]

∥☆過路亽.° 提交于 2019-11-27 21:55:13
Back at the PDC in 2008, in the C# futures talk by Anders Hejlsberg he talked about rewriting the C# compiler and providing a "compiler as a service" I certainly got the impression at the time that they were targeting the C# 4.0 timeframe for this.... Well, does anyone know what the state of this is? it doesn't seem to be there in the CTP and there is almost no information on the WEB apart from links to the 2008 PDC session video (roughly an hour in). Has this initiative gone dark? Certainly not C# 4.0. We are just finishing up the last few bug fixes for C# 4.0. This direction for the toolset

Can I use Roslyn for compile time code rewriting?

牧云@^-^@ 提交于 2019-11-27 21:20:28
For example I have class Foo: INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public int Bar {get;set;} } Can I get the Foo class AST and rewrite Bar, in compile time, to public string Bar { get { return this.bar; } set { if (value != this.bar) { this.phoneNumberValue = value; PropertyChanged(this, new PropertyChangedEventArgs("Bar")); } } } . Compile time re-writing isn't directly supported by Roslyn today, but syntactic and semantic transformations definitely are. In fact, take a look at the "ImplementNotifyPropertyChanged" sample included in the CTP to see

What / why is Roslyn “needed” in /bin folder of Asp.Net

杀马特。学长 韩版系。学妹 提交于 2019-11-27 20:20:52
There are a bunch of related questions on this, though most of the answers define Roslyn and/or provide a "fix" to some issue ( exe , with hosting providers, etc.) What I can't seem to track down is the "why" and "what for" (perhaps only in the context of ASP.Net MVC/Web API) in /bin/roslyn . I ran in to similar issues (hosting - .exe restrictions, support for 4.6 , etc.) and my "fix" was to "just deploy to Azure" (of course everything works without a hitch). But really, this doesn't answer: why are they needed? does this mean that the they are used for runtime compilation (my brain points to