roslyn

Microsoft Roslyn vs. CodeDom

烂漫一生 提交于 2019-11-27 02:34:51
From a press release yesterday on InfoWorld regarding the new Microsoft Roslyn : The most obvious advantage of this kind of "deconstructed" compiler is that it allows the entire compile-execute process to be invoked from within .Net applications. Hejlsberg demonstrated a C# program that passed a few code snippets to the C# compiler as strings; the compiler returned the resulting IL assembly code as an object, which was then passed to the Common Language Runtime (CLR) for execution. Voilà! With Roslyn, C# gains a dynamic language's ability to generate and invoke code at runtime. I've been able

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

我怕爱的太早我们不能终老 提交于 2019-11-27 01:55:11
问题 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

Maybe a C# compiler bug in Visual Studio 2015

久未见 提交于 2019-11-27 01:41:01
I think this is a compiler bug. The following console application compiles und executes flawlessly when compiled with VS 2015: namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var x = MyStruct.Empty; } public struct MyStruct { public static readonly MyStruct Empty = new MyStruct(); } } } But now it's getting weird: This code compiles, but it throws a TypeLoadException when executed. namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var x = MyStruct.Empty; } public struct MyStruct { public static readonly MyStruct? Empty = null; }

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

会有一股神秘感。 提交于 2019-11-26 23:25:00
问题 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

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

给你一囗甜甜゛ 提交于 2019-11-26 23:06:52
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . 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

Is nameof() evaluated at compile-time?

流过昼夜 提交于 2019-11-26 22:26:08
In C# 6, you can use the nameof() operator to get a string containing the name of a variable or a type. Is this evaluated at compile-time, or at runtime via some Roslyn API? i3arnon Yes. nameof() is evaluated at compile-time. Looking at the latest version of the specs: The nameof expression is a constant. In all cases, nameof(...) is evaluated at compile-time to produce a string. Its argument is not evaluated at runtime, and is considered unreachable code (however it does not emit an "unreachable code" warning). From nameof operator - v5 You can see that with this TryRoslyn example where this:

How to suppress code analysis messages for all type members?

陌路散爱 提交于 2019-11-26 21:32:44
问题 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

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

我与影子孤独终老i 提交于 2019-11-26 21:09:46
问题 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

Can I use Roslyn for compile time code rewriting?

爱⌒轻易说出口 提交于 2019-11-26 20:37:44
问题 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")); } } } . 回答1: Compile time re-writing isn't directly supported by Roslyn today, but syntactic and semantic transformations

How to compile a C# file with Roslyn programmatically?

五迷三道 提交于 2019-11-26 19:23:36
问题 I read that you can't compile C# 6.0 with CSharpCodeProvider and therefor trying to do with with Roslyn. But I can't find a good example how to load a file and then compile it to a dll. How should I write something similar to this code with Roslyn? Or is there some other way to do it? Now when I try to compile files that contain reference to projects with C# 6.0 code it just say "The type or namespace name 'x' does not exist in the namespace 'y' (are you missing an assembly reference?)"