roslyn

Access to .config files in Roslyn REPL

余生长醉 提交于 2019-11-30 15:32:59
问题 Using the Roslyn June 2012 CTP: Is there a way to provide the Roslyn C# Interactive/REPL with a .config file for the code being explored? A simple example scenario is code which depends on a connection string which it would usually obtain from the app.config/web.config. 回答1: This is actually possible now (and may have been at the time this question was asked). Simply create a LoadConfig.csx file with the following: #r "System.Configuration" using System; using System.IO; using System.Linq;

Sort and remove (unused) using statements Roslyn script/code?

心已入冬 提交于 2019-11-30 13:09:04
Sort and remove (unused) using statements Roslyn script/code? I'm looking for some .NET/Roslyn (compiler as service) code that can run through a project and sort and remove unused using statements. I believe this is possible with Roslyn? Can anyone point me to code that could do this rewrite? This is a feature in Visual Studio, but academically I think you would collect using statements from your SyntaxTree like this: var usings = syntaxTree.Root.DescendentNodes().Where(node is UsingDirectiveSyntax); ...and compare that to the namespaces resolved by the symbol table like this: private static

scriptcs hosting - Advantages over Roslyn

走远了吗. 提交于 2019-11-30 10:48:32
问题 If I want to support scripting in my application, does scriptcs offer any particular advantages over just using the plain vanilla Roslyn script engine? 回答1: Unfortunately there's not much documentation on hosting scriptcs yet, but I'll try to give you a short summary. Hosting scriptcs in your application provides several features that vanilla Roslyn doesn't: Pluggable Engines While scriptcs comes with the Roslyn and Mono engines by default, you can easily replace it with another engine, i.e.

Loading an assembly generated by the Roslyn compiler

我的梦境 提交于 2019-11-30 09:50:24
I'm generating a Greeter.dll using the Roslyn compiler. My problem occurs trying to load the DLL file. Here's the code: using System; using Roslyn.Compilers; using Roslyn.Compilers.CSharp; using System.IO; using System.Reflection; using System.Linq; namespace LoadingAClass { class Program { static void Main(string[] args) { var syntaxTree = SyntaxTree.ParseCompilationUnit(@" class Greeter { static void Greet() { Console.WriteLine(""Hello, World""); } }"); var compilation = Compilation.Create("Greeter.dll", syntaxTrees: new[] { syntaxTree }, references: new[] { new AssemblyFileReference(typeof

Roslyn Code Action: How to check if preview or real execution?

眉间皱痕 提交于 2019-11-30 09:28:10
问题 I am currently experimenting with Roslyn and Code Actions, more specific Code Refactorings. It feels kind of easy, but I have a difficulty I cannot solve. Code actions are executed once against a dummy workspace as a "preview" option, so that you can see the actual changes before you click the action and execute it against the real workspace. Now I am dealing with some things Roslyn can't really do (yet), so I am doing some changes via EnvDTE . I know, it's bad, but I couldn't find another

Where has the Code Analysis window gone?

与世无争的帅哥 提交于 2019-11-30 07:47:48
In Visual Studio 2013, I used the Code Analysis window to provide reports to both the Development and Management teams. In Visual Studio 2015 Enterprise RTM, these errors have returned to the error window and I can no longer just see CA issues for a single project, or filter them by type. Is there a way to bring the Code Analysis window back? Visual Studio Code Analysis has been merged with Intellisense and can now be viewed from the Error window. When you select "Build+Intellisense" or "Intellisense" your code analysis warnings will show up there. You no longer need to build your solution to

params overload apparent ambiguity - still compiles and works?

梦想与她 提交于 2019-11-30 06:34:32
We just found these in our code: public static class ObjectContextExtensions { public static T Find<T>(this ObjectSet<T> set, int id, params Expression<Func<T, object>>[] includes) where T : class { ... } public static T Find<T>(this ObjectSet<T> set, int id, params string[] includes) where T : class { ... } } As you can see, these have the same signature except for the params . And they're being used in several ways, one of them: DBContext.Users.Find(userid.Value); //userid being an int? (Nullable<int>) which, strangely enough to me, resolves to the first overload. Q1: Why doesn't this

How do I compile a C# solution with Roslyn?

吃可爱长大的小学妹 提交于 2019-11-30 06:21:56
问题 I have a piece of software that generates code for a C# project based on user actions. I would like to create a GUI to automatically compile the solution so I don't have to load up Visual Studio just to trigger a recompile. I've been looking for a chance to play with Roslyn a bit and decided to try and use Roslyn instead of msbuild to do this. Unfortunately, I can't seem to find any good resources on using Roslyn in this fashion. Can anyone point me in the right direction? 回答1: You can load

Was C# compiler written in C++?

喜欢而已 提交于 2019-11-30 06:03:53
Was C# compiler written in C++? Kent Boogaart Yes, but there are plans to write a C# compiler in C#, which I believe was discussed in this podcast . Yes. The Mono C# compiler is written in C#. Kakashi The .NET framework was written in Simple Managed C (SMC) History During the development of the .NET Framework, the class libraries were originally written using a managed code compiler system called Simple Managed C (SMC).In January 1999, Anders Hejlsberg formed a team to build a new language at the time called Cool, which stood for "C-like Object Oriented Language".[16] Microsoft had considered

Getting debugger context in C# interactive

与世无争的帅哥 提交于 2019-11-30 05:42:10
C# Interactive seems a lot more powerful than the Immediate Window (at least it handles lambda expressions that are often used in LINQ - see Visual Studio debugging "quick watch" tool and lambda expressions ), but it looks like it can't be used as a replacement as it doesn't know about the debugger context. Is there a way to have access to the debugger context? I've seen Getting debugger context in F# interactive and it might require the same things, but maybe there are new/different things available. http://extendedimmediatewin.codeplex.com/ could be useful but looks quite dead, although