Question to synthesized GeneratedNames for yield statement #68664
Unanswered
daveMueller
asked this question in
General
Replies: 2 comments
-
Sorry, but the generation of closures is rather complicated and is an implementation detail (subject to change). Someone would have to dig into the compiler code, so we're unlikely to be able to help with this. I'll move the issue to a discussion |
Beta Was this translation helpful? Give feedback.
0 replies
-
Would it be possible to lookup the compiler generated name using reflection ? using System;
using System.Collections.Generic;
using static System.Console;
var seqA = A.All ();
var typeA = seqA.GetType ();
var nameA = typeA.Name;
WriteLine ($"A: {nameA}"); // <All>d__0
var seqB = B.All ();
var typeB = seqB.GetType ();
var nameB = typeB.Name;
WriteLine ($"B: {nameB}"); // <All>d__1
public class A {
public static IEnumerable<string> All() {
yield return "1";
}
}
public class B {
string Read;
public static IEnumerable<string> All() {
yield return "1";
}
} Greetings from KA to RA .. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I would need some clarification on how the synthesized names are generated for yield statements. We have a bug in our
coverage tool coverlet-coverage/coverlet#1484 because of this.
To be more precise, when having a simple class like the following
the compiler is adding a nested type called
<All>d__0
So now when I add a simple field like the following
the compiler is adding nested type called
<All>d__1
Our algorithem currently only counts methods for the ordinal number and I guess this is the problem. What exactly (fields, properties, ...) do I need to consider when computing this generated name?
Beta Was this translation helpful? Give feedback.
All reactions