MaterialColorUtilities icon indicating copy to clipboard operation
MaterialColorUtilities copied to clipboard

Rename/alias Scheme<T>.Enumerate to GetEnumerator

Open JonathanBout opened this issue 6 months ago • 0 comments

To support a cleaner foreach loop It'd be great to rename (or alias for backwards compatibility) Scheme<TColor>.Enumerate to Scheme<TColor>.GetEnumerator.

// old
foreach (var (key, color) in scheme.Enumerate())
{
    // ...
} 

// new
foreach (var (key, color) in scheme)
{
    // ...
}

This makes the use of it more C#-like. Just the method should be enough, but you might as well implement IEnumerable<TColor> which supplies this exact method, and makes it LINQ-compatible.

I think it can be easily done from the source generator, by simply adding 1 extra line to the generated code:

public IEnumerator<KeyValuePair<string, TColor>> GetEnumerator() => Enumerate();

JonathanBout avatar Jan 09 '24 14:01 JonathanBout