public IEnumerator<T> GetEnumerator()
{
object? storeValue = _store.GetParsedValues(_descriptor);
+ return storeValue is null ?
+ ((IEnumerable<T>)Array.Empty<T>()).GetEnumerator() : // use singleton empty array enumerator
+ Iterate(storeValue);
- if (storeValue == null)
- {
- yield break;
- }
-
- List<object>? storeValues = storeValue as List<object>;
-
- if (storeValues == null)
+ static IEnumerator<T> Iterate(object storeValue)
{
- Debug.Assert(storeValue is T);
- yield return (T)storeValue;
- }
- else
- {
- // We have multiple values. Iterate through the values and return them.
- foreach (object item in storeValues)
+ if (storeValue is List<object> storeValues)
+ {
+ // We have multiple values. Iterate through the values and return them.
+ foreach (object item in storeValues)
+ {
+ Debug.Assert(item is T);
+ yield return (T)item;
+ }
+ }
+ else
{
- Debug.Assert(item is T);
- yield return (T)item;
+ Debug.Assert(storeValue is T);
+ yield return (T)storeValue;
}
}
}