Make SyntaxList implement IEnumerable<SyntaxElement>
viclin-msft opened this issue · comments
Currently, SyntaxList
does not support LINQ queries, e.g.
SyntaxList elements = ...
elements.Select(x => x.ToString());
This can be supported by having the class implement IEnumerable<SyntaxElement>
.
It is comparable to Microsoft.CodeAnalysis.SyntaxList.
My current workaround:
private IEnumerable<SyntaxElement> GetEnumerableElements(SyntaxList list)
{
foreach (var element in list)
{
yield return element.GetChild(0); // element is SeparatedElement; the first child is the actual item in list
}
}
SyntaxList elements = ...
GetEnumerableElements(elements).Select(x => x.ToString());
The type SyntaxList
is an abstract base for SyntaxList<T>
. SyntaxList<T>
already does implement IEnumerable<T>
via IReadOnlyList<T>
. However, if both the base type and subtype implement different IEnumerable<T>
it confuses LINQ and blocks uses of extension methods on any SyntaxList<T>
subtype.
SyntaxList
does implement the enumerable pattern, though. That lets you use foreach, but not other LINQ methods.