ashmind / sharplab Goto Github PK
View Code? Open in Web Editor NEW.NET language playground
Home Page: https://sharplab.io
License: BSD 2-Clause "Simplified" License
.NET language playground
Home Page: https://sharplab.io
License: BSD 2-Clause "Simplified" License
Given program:
using System;
public class C {
public int M() {
string n = GetDefault<string>();
switch(n) {
case null: return 1;
case "foo": return 2;
default: return 3;
}
}
private T GetDefault<T>() {
return default(T);
}
}
decompilation to C# returns:
public class C
{
public int M()
{
string @default = this.GetDefault<string>();
string text = @default;
int result;
if (text != null)
{
if (!text == "foo")
{
result = 3;
}
else
{
result = 2;
}
}
else
{
result = 1;
}
return result;
}
private T GetDefault<T>()
{
return default(T);
}
}
Line if (!text == "foo")
contains syntax error, it should be decompiled to if (text != "foo")
or at least to if(! (text == "foo") )
.
Given
public class MyClass (string name) {
private string name2 = name;
}
Getting
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
public class MyClass
{
private string name2 = name;
public MyClass(string name)
{
}
}
I've fixed links to commits in #10. Links to authors still don't work (I couldn't see how to get the files in App_Data to get website to run): might be easiest to remove these links to authors
When Roslyn throws an exception while compiling some code (for example: dotnet/roslyn#13365), the stack trace of the exception is shown with all its lines mushed together as if it was one line:
It would be better if the newlines in the stack trace were preserved, for example by using the whitespace: pre
style:
[07/04/2015 07:30:49 > 95cf44: INFO] Syncing D:\home\site\!roslyn-sources\core-clr
[07/04/2015 07:30:51 > 95cf44: ERR ] From https://github.com/dotnet/roslyn
[07/04/2015 07:30:51 > 95cf44: ERR ] * branch core-clr -> FETCH_HEAD
[07/04/2015 07:31:13 > 95cf44: ERR ]
[07/04/2015 07:31:13 > 95cf44: ERR ] *** Please tell me who you are.
[07/04/2015 07:31:13 > 95cf44: ERR ]
[07/04/2015 07:31:13 > 95cf44: ERR ] Run
[07/04/2015 07:31:13 > 95cf44: ERR ]
[07/04/2015 07:31:13 > 95cf44: ERR ] git config --global user.email "[email protected]"
[07/04/2015 07:31:13 > 95cf44: ERR ] git config --global user.name "Your Name"
[07/04/2015 07:31:14 > 95cf44: ERR ]
[07/04/2015 07:31:14 > 95cf44: ERR ] to set your account's default identity.
[07/04/2015 07:31:14 > 95cf44: INFO] Building D:\home\site\!roslyn-sources\core-clr
[07/04/2015 07:31:14 > 95cf44: ERR ] Omit --global to set the identity only in this repository.
[07/04/2015 07:31:14 > 95cf44: ERR ]
[07/04/2015 07:31:14 > 95cf44: ERR ] fatal: unable to auto-detect email address (got 'tryroslyn@XXXXXXXXXXXXXXX.(none)')
(XXX above masks some id, not sure of security implications of sharing it)
Putting the following input in the standard C class/M method
Func<int, int> getInt = s => s;
var list = new [] { 1, 2, 3, getInt(1) };
Console.WriteLine(list[3]);
results in decompiled C# output containing
int[] array = new int[] {
1,
2,
3,
0
};
Console.WriteLine(array[3]);
in debug mode and
Console.WriteLine(new int[] {
1,
2,
3,
0
}[3]);
in release mode. The IL output looks like it does show a lambda call.
This would be pretty epic https://github.com/dotnet/jitutils
/cc @benaadams @jamesqo
IL is fine, but C# and VB.NET is missing the explicit cast.
It would be really interesting to be able to use TryRoslyn to learn about differences in the output IL between Roslyn and the C# 5.0 compiler. This would require allowing the user to choose "IL" on the right-hand instead of Decompiled C#, and allowing the user to choose pre-Roslyn versions of the compiler on the left-hand-side.
Roslyn updated with support for code like this:
using System;
public class C {
public ref int M() {
int [] numbers = { 0b1, 0b0___01 };
return ref numbers;
}
}
(released in April)
Please add its support to TryRoslyn.
What license is this code?
using System;
public class Point(int x)
{
public int X { get; } = x;
public int M(Point p)
{
return (p?.X).GetValueOrDefault();
}
}
is decompiled to
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[module: UnverifiableCode]
public class Point
{
[CompilerGenerated]
private readonly int <X>k__BackingField;
public int X
{
[CompilerGenerated]
get
{
return this.<X>k__BackingField;
}
}
public Point(int x)
{
this.<X>k__BackingField = x;
base(); // This is not valid C#, but it represents the IL correctly.
}
public int M(Point p)
{
return p != null ? new int?(p.X) : null.GetValueOrDefault();
}
}
Should be
return (p != null ? new int?(p.X) : null).GetValueOrDefault();
When already on the site, if I try to navigate to a saved bookmark, the browser's location bar is updated, but the contents aren't - I have to open each bookmark in a new tab to get the right contents. However, if I hit enter on the changed location bar, the contents are updated.
Looks not so hard to support :)
Also ILSpy supports decompilation to VB, but produced code just sucks a lot...
With the default code in the left pane, the features/extensionEverything
branch fails with this exception. Whether this is a fault with this or with that branch I'm not sure.
An error occurred when trying to create a controller of type 'RoslynController'. Make sure that the controller has a parameterless public constructor.
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
at System.Web.Http.Tracing.Tracers.HttpControllerActivatorTracer.<>c__DisplayClass2.<System.Web.Http.Dispatcher.IHttpControllerActivator.Create>b__0()
at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
at System.Web.Http.Tracing.Tracers.HttpControllerActivatorTracer.System.Web.Http.Dispatcher.IHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)
at System.Web.Http.Tracing.Tracers.HttpControllerDescriptorTracer.<>c__DisplayClass2.<CreateController>b__0()
at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
at System.Web.Http.Tracing.Tracers.HttpControllerDescriptorTracer.CreateController(HttpRequestMessage request)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
See for example this. Lots of NOP instructions in the generated IL and there is no difference when choosing Debug or Release.
module M
' ...
end module
Do not compiles because of:
error BC35000: Requested operation is not available because the runtime library function 'Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute..ctor' is not defined.
Roslyn script mode changes code too much -- I should do my own rewriting, putting statements/expressions into method body directly without rewriting them to fields.
Requested in dotnet/roslyn#14582.
(Might be worth making package/ref list easily configurable, even if not user-configurable)
When compiling code on Roslyn's master branch, I get the following error:
An error occurred when trying to create a controller of type 'RoslynController'. Make sure that the controller has a parameterless public constructor.
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
at System.Web.Http.Tracing.Tracers.HttpControllerActivatorTracer.<>c__DisplayClass2.<System.Web.Http.Dispatcher.IHttpControllerActivator.Create>b__0()
at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
at System.Web.Http.Tracing.Tracers.HttpControllerActivatorTracer.System.Web.Http.Dispatcher.IHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)
at System.Web.Http.Tracing.Tracers.HttpControllerDescriptorTracer.<>c__DisplayClass2.<CreateController>b__0()
at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
at System.Web.Http.Tracing.Tracers.HttpControllerDescriptorTracer.CreateController(HttpRequestMessage request)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
Compiling using Release (NuGet) works fine.
(,,,): error : An error occurred when trying to create a controller of type 'RoslynController'. Make sure that the controller has a parameterless public constructor.
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
at System.Web.Http.Tracing.Tracers.HttpControllerActivatorTracer.<>c__DisplayClass2.<System.Web.Http.Dispatcher.IHttpControllerActivator.Create>b__0()
at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
at System.Web.Http.Tracing.Tracers.HttpControllerActivatorTracer.System.Web.Http.Dispatcher.IHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)
at System.Web.Http.Tracing.Tracers.HttpControllerDescriptorTracer.<>c__DisplayClass2.<CreateController>b__0()
at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
at System.Web.Http.Tracing.Tracers.HttpControllerDescriptorTracer.CreateController(HttpRequestMessage request)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
Probably related to #24.
to use other branch like roslyn/local-functions
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.