Roslyn
SharpLab
Our great sponsors
Roslyn | SharpLab | |
---|---|---|
87 | 65 | |
15,917 | 1,824 | |
1.4% | - | |
10.0 | 9.1 | |
about 10 hours ago | 21 days ago | |
C# | C# | |
MIT License | BSD 2-clause "Simplified" License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
Roslyn
-
Method overloading error in 2022 and I don't know why.
Local functions do not support overloading
-
Why does foreach on arrays and strings get lowered into a while loop that ignores IEnumerable, even though both classes implement it?
Honestly, I don't have a clue why these would be different. I found the relevant Roslyn code here. You can see on line 719 that this is definitely intentional:
- .Net 6.0 - The new Program.cs "flat" style - too implicit/magic?
-
Why is Python so popular?
compiler: https://github.com/dotnet/roslyn
-
How to call a variable from a string, if that make sense lol
Why not use Roslyn Scripting…you can pretty much do any kind of dynamic evaluation with this and it does not require any reflection. https://github.com/dotnet/roslyn/blob/main/docs/wiki/Scripting-API-Samples.md you can add the support via a Nuget.
-
What’s the maximum number of arguments for method in C# and in .NET?
It was discussed at one point: https://github.com/dotnet/roslyn/issues/5058
-
What parsing techniques do you use to support a good language server?
It must be a fairly large echo chamber since it has room for Clang, GCC, V8, OpenJDK, Roslyn, etc. (The Zend parser for PHP seems to use some flavor of YACC, but given PHP, I don't know if that strengthens or weakens my point.)
-
Why is no-one using Roslyn token-based code generation with Source Generators?
I'm planning to rewrite all of our company's old T4-based codegen tools into Source Generators. I've been looking at how other Source Generators are implemented and what surprised me is that everyone seems to assemble the output code manually as text with string builders or at best some simple templating engine (eg. Scriban). I expected that I would see a lot of projects assembling their output code from Roslyn tokens and then using Roslyn's formatter to produce the actual code that can be emitted into the output file(s), like this article demonstrates. No-one seem to be doing that though. Why?
-
Actix Web v4.0 (Rust)
Clearly nobody ever manages to use this Go thing with over 700: https://github.com/golang/go/issues. Or .net, over 5000 issues for the compiler alone: https://github.com/dotnet/roslyn. I'd guess stuff like Java, glibc would be similar if they used github
SharpLab
-
Switch is Faster than If (in C#)
With sharplab.io you can see the C#-code which is produced during lowering. When we paste our original GetMonthIndexSwitch in there, you will see that this is rewritten into if statements.
-
Having Trouble Enabling Latest Features in C# 11 Preview
It does not sort your issue out but if all you want to do is check out the latest language C# 11 Preview feature, you can run main branch of dotnet as of 19 Apr 2022 at sharplab.io without installing anything.
-
Anyone know of some resource to get the low-level syntax for syntactic sugar?
If that is the term that would help me do something equivalent to godbolt.org or https://sharplab.io/ against other runtimes.
-
Asynchronous programming in C#
The above example shows state machine that was generated by a source code containing only one await keyword. When we use await more than once in the given method, the state machine ends up with more complicated MoveNext version. If you would like to experiment with it, I recommend https://sharplab.io/ for viewing Intermediate Language or a downloadable tool ILSpy which has similar functionality.
-
Come on, a whole modulo operation? What are we running on, a super computer??
I have never worked with C#, so I can't really tell you unfortunately. If I inspect the "JIT ASM" of the following code in sharplab.io, in Release mode, it seems that similar optimizations are performed. static bool IsEvenA(int n) { return (~n & 1) != 0; } static bool IsEvenB(int n) { return n %2 == 0; }
-
Visitor pattern performance problems?
The other thing that may hint to what is going on is to use sharplab.io (https://sharplab.io) and decompile to C# to get an imperative view on your code, which will be closer to the reality of how it is executed. This may be overwhelming for the full code so you may need to target specific snippets.
-
If you’re a beginner and you think your code is bad, look at mine from 2 years ago when I started
Great tool to inspect the lowered C# version of your code: https://sharplab.io/
-
How do I go about programming a windows form on my phone
sharplab.io
-
What do you think about file scoped classes?
There is one exception I have encountered: you're limited to a single file (e.g. because you're using https://sharplab.io/) and you need to to do something weird (typically using a preview compiler feature without running on a preview runtime) by adding a type from a specific namespace (typically System.Runtime.CompilerServices).
-
This question need not be answered, but what names do automated backing fields get?
If your ever curious about what your code compiles to you can just throw it into sharplab.io. There you can see things like foreach loops are in fact just for loops and for loops are just while loops to the compiler. It's a great tool to use if you're ever caught wondering whether one implementation of your method is faster than another.
What are some alternatives?
Mono-basic - Visual Basic Compiler and Runtime
F# - Please file issues or pull requests here: https://github.com/dotnet/fsharp
Bridge.NET - :spades: C# to JavaScript compiler. Write modern mobile and web apps in C#. Run anywhere with Bridge.NET.
MSBuild - The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
ClojureCLR - A port of Clojure to the CLR, part of the Clojure project
interactive - .NET Interactive takes the power of .NET and embeds it into your interactive experiences. Share code, explore data, write, and learn across your apps in ways you couldn't before.
Roslyn-linq-rewrite - Compiles C# code by first rewriting the syntax trees of LINQ expressions using plain procedural code, minimizing allocations and dynamic dispatch.
Fable: F# |> BABEL - F# to JavaScript Compiler
VisualFSharp - The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
.NET Runtime - .NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
csharp-source-generators - A list of C# Source Generators (not necessarily awesome) and associated resources: articles, talks, demos.