The .NET Compiler Platform ("Roslyn") provides open-source C# and Visual Basic compilers with rich code analysis APIs.
dotnet-maestro[bot] on darc-main-01aa6f43-60c3-41ad-b4bb-10decf78d278
Update dependencies from https:… (compare)
@VBAndCs Note that your extension method is on
(int, int, int)
, but you're calling it on(int, int)
just above. Those are different types
I have a two-item version.
using System;
using System.Collections;
using System.Runtime.CompilerServices;
foreach (int i in 20..10)
Console.WriteLine(i);
foreach (int i in (10, -10))
Console.WriteLine(i);
foreach (int i in (-10, 10, 3))
Console.WriteLine(i);
public static class Extensions
{
public static IEnumerator GetEnumerator(this System.Range range)
{
int start = range.Start.Value;
int end = range.End.Value;
if (end > start)
for (int i = start; i <= end; i++)
yield return i;
else
for (int i = start; i >= end; i--)
yield return i;
}
public static IEnumerator GetEnumerator(this System.ValueTuple<int, int> range)
{
int start = range.Item1;
int end = range.Item2;
if (end > start)
for (int i = start; i <= end; i++)
yield return i;
else
for (int i = start; i >= end; i--)
yield return i;
}
public static IEnumerator GetEnumerator(this System.ValueTuple<int, int, int> range)
{
int start = range.Item1;
int end = range.Item2;
int step = range.Item3;
if (step > 0)
for (int i = start; i <= end; i+=step)
yield return i;
else
for (int i = start; i >= end; i += step)
yield return i;
}
}
Thanks :)
Yeah I understand. Although a large portion of System.Reflection is to do with statically available info (obviously I don't expect roslyn to be able to give me runtime values if there isn't a program running, so there's no representation of CreateInstance, SetValue, GetValue etc.).
For example PropertyInfo in reflection, and IPropertySymbol in Roslyn
This is the stuff I want to hear about :D. I just want to know if these kinds of relationships are documented somewhere - and is it a value that the roslyn team hold or is any symmetry between the APIs incidental?
IsNullableTypeOrTypeParameter (https://sourceroslyn.io/#Microsoft.CodeAnalysis.CSharp/Symbols/TypeSymbolExtensions.cs,113) checks if a constraint type is a nullable type.
But how is this ever possible since structs can't be constraints? Is it only if the constraint is defined in a different language?
lower
a code block to a classic simple C#/VB code and show it in a readoly code window. Pattern matching expressions are in top of things that may need explanation
. I may go far and say every new concept since Roslyn can be considered hard and nee to be explained. This can be a useful educational feature, and ease the pain for new team members that joins a large project. VS offers to simplify expressions which in most cases means shorten them into a complex modern syntax! We may need an action on the opposite direction. This seems a lot of work, but it can make use of the Roslyn code itself if it lowers these statements.