Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 22:41
    tmat synchronize #62840
  • 22:34
    msftbot[bot] milestoned #64554
  • 22:34
    msftbot[bot] milestoned #64554
  • 22:34

    JoeRobich on main

    Publish pr validation packages Merge pull request #64554 from … (compare)

  • 22:34
    JoeRobich closed #64554
  • 22:31
    runfoapp[bot] edited #64047
  • 22:31
    runfoapp[bot] edited #61367
  • 22:31
    runfoapp[bot] edited #61367
  • 22:28
    JoeRobich edited #64554
  • 22:28
    RikkiGibson assigned #64380
  • 22:27
    dotnet-issue-labeler[bot] labeled #64582
  • 22:27
    JoeRobich review_requested #64582
  • 22:27
    JoeRobich opened #64582
  • 22:26
    jcouv assigned #64578
  • 22:25
    tmat synchronize #64221
  • 22:24

    JoeRobich on jorobich

    Update NavigateTo tests to supp… (compare)

  • 22:23
    AlekseyTs assigned #24135
  • 22:23
    AlekseyTs unassigned #24135
  • 22:19
    RikkiGibson edited #60819
  • 22:18
    RikkiGibson synchronize #64414
Mohammad Hamdy Ghanem
@VBAndCs
untitled12.jpg
Remove unused local function? This is too scary!
Bernd Baumanns
@bernd5
what is scary?
Paul M Cohen
@paul1956
For VB functions that are Event Handlers appear as unused and VS 2022 removes handles clauses sometimes so the function would be deleted.
CyrusNajmabadi
@CyrusNajmabadi
That's a bug if so. Please file.
Jon Evans
@glitch100

Morning all.

Is it still the case that debugging Roslyn Analyzers/ CodeFixProviders can only be done via the VSIX Extension project? Is it possible to debug a unit test that is written? As in step into the Analyzer code?

Joe4evr
@Joe4evr
I've always used a unit test to step into analyzer code
never heard of a VSIX project being "the only way" to debug an analyzer
Jon Evans
@glitch100
Do you use a specific helper method to invoke your Analyzer code?
Jon Evans
@glitch100
My goodness
Antony Male
@canton7
I took that and modified it a bunch, ended up with something quite nice
Joe4evr
@Joe4evr
and it needs to be told which assembly to load the analyzers from + possible dependencies, so there's room for improvement
Jon Evans
@glitch100
Checking them atm - cheers all
HaloFour
@HaloFour
Mohammad Hamdy Ghanem
@VBAndCs
I am using this extension method in c#:
    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;
    }
It allows me to use this code:
foreach (int i in (-10, 10, 3))
    Console.WriteLine(i);
I imported this method from C# to VB and I can also use it in for each:
image.png
Mohammad Hamdy Ghanem
@VBAndCs
image.png
But, this doesn't work:
    Sub Main(args As String())
        For Each i In (1, 10, 2).GetEnumerator()
            Console.WriteLine(i)
        Next
The starnge thing is that the opposite happens if I define the extensoin method in vb code!
Imports System.Runtime.CompilerServices

Public Module Tools
    <Extension>
    Public Iterator Function GetEnumerator(range As ValueTuple(Of Integer, Integer, Integer)) As IEnumerable
        Dim start = range.Item1
        Dim [end] = range.Item2
        Dim [step] = range.Item3

        If ([step] > 0) Then
            For i = start To [end] Step [step]
                Yield i
            Next
        Else
            For i = start To [end] Step [step]
                Yield i
            Next
        End If
    End Function

End Module
In this case, the (1, 10, 2).GetEnumerator()expression works, but (1, 10, 2) doesn't!
Why?
image.png
Mohammad Hamdy Ghanem
@VBAndCs
image.png
Yair Halberstadt
@YairHalberstadt
@VBAndCs because extension GetEnumerator is c# only
It's a C# 9.0 feature (which I implemented) and I never implemented it for VB.
Mohammad Hamdy Ghanem
@VBAndCs
This answers why it doesn't work when it is written in VB. But it works for vb when I reference it from C#. I am asking why?
And why .GetEnumerator works if it's written in vb and doesn't work in C#?
Is it ok to write a GetEnumerator function but can't call it directly?
Antony Male
@canton7
(Note that since your extension methods return the non-generic IEnumerable, you'll be boxing an int on every iteration of the loop, which is a fair chunk of unneeded garbage)
Mohammad Hamdy Ghanem
@VBAndCs
Thanks. I wasn't sure that IEnumerable<int> works and left it to try later, since I am just exploring new possibilities.
Yair Halberstadt
@YairHalberstadt
@VBAndCs what matters is which language the foreach is in, not which language has the GetEnumerator
It's a change to the spec for how foreach binds. There's nothing special about the GetEnumerator method. Just C# recognizes certain patterns when lowering foreach and VB a different set.
Antony Male
@canton7
My understanding of the question was that VB did manage to use an extension GetEnumerator, but only when the extension GetEnumerator was written in C#, not in VB?
Yair Halberstadt
@YairHalberstadt
If it did, that would be truly magical
Perhaps little mice sneaking in whilst I was sleeping and writing the code for that.
Mohammad Hamdy Ghanem
@VBAndCs
Seems that vb for each was able to consume C# getEnemurator b4 it was added to C# :). The question is why it can't consume the vb one? This is the code that vb generates:
[StandardModule]
public sealed class Tools
{
    [IteratorStateMachine(typeof(VB$StateMachine_0_GetEnumerator))]
    public static IEnumerable GetEnumerator(this (int, int, int) range)
    {
        VB$StateMachine_0_GetEnumerator vB$StateMachine_0_GetEnumerator = new VB$StateMachine_0_GetEnumerator(-2);
        vB$StateMachine_0_GetEnumerator.$P_range = range;
        return vB$StateMachine_0_GetEnumerator;
    }
}
I can't see what c# generates (except in il which I don't understand).
So, what is wrong with the vb state machine?
Yair Halberstadt
@YairHalberstadt
@VBAndCs I don't understand what you're saying by "Seems that vb for each was able to consume C# getEnemurator b4 it was added to C#"
Antony Male
@canton7
One difference is that it's missing the [Extension] attribute?
Mohammad Hamdy Ghanem
@VBAndCs

@VBAndCs I don't understand what you're saying by "Seems that vb for each was able to consume C# getEnemurator b4 it was added to C#"

Try it on yout machine. The getenumerator extension method works in vb when it is written in C# but doesn't work when it is written in VB! For Each in vb doesn what foreach in c# does in this matter, but seems the difference is in the generated state machine in both languages, or the way that Yield is implemented in both. Maybe it is a different attribute sued or a missing one. Seems something that can be fixed in vb to have the same functionality as c#.

Mohammad Hamdy Ghanem
@VBAndCs

One difference is that it's missing the [Extension] attribute?

this is the code I get back from ILSpy. I use the Extension attribute in the code as I posted before, and I show you that calling the .GetEnumerator explicitly works only for the one written in VB not C#.

Mohammad Hamdy Ghanem
@VBAndCs
Another thing to fix in C#: this code gives an error:
var e = (1, 2).GetEnumerator();
although I defined a GetEnumerator extension method!
Making it works on foreach is nice, but it should also work everywhere.
@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