Skip to content

Emitting "Invalid" Attribute #185

@JasonBock

Description

@JasonBock
#nullable enable

public class HasAsyncIteratorStateMachine<T>
{
    private ValueTask<bool> WaitToReadAsync(CancellationToken cancellationToken = default) =>
        ValueTask.FromResult(true);
	
    private bool TryRead([MaybeNullWhen(false)] out T item)
    {
        item = default!;
        return true;
    }
    
    public virtual async IAsyncEnumerable<T> ReadAllAsync(
        [EnumeratorCancellation] CancellationToken cancellationToken = default)
    {
        while (await WaitToReadAsync(cancellationToken).ConfigureAwait(false))
        {
            while (TryRead(out T? item))
            {
                yield return item;
            }
        }
    }
}

The ReadAllAsync() has an [AsyncIteratorStateMachine] attribute, but this shouldn't be emitted in the mock, similar to other attributes that are ignored in AttributeDataExtensions.GetDescription(), like IteratorStateMachineAttribute.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions