// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace CommunityToolkit.Mvvm.Messaging.Messages;
///
/// A for request messages that can receive multiple replies, which can either be used directly or through derived classes.
///
/// The type of request to make.
public class CollectionRequestMessage : IEnumerable
{
private readonly List responses = new();
///
/// Gets the message responses.
///
public IReadOnlyCollection Responses => this.responses;
///
/// Replies to the current request message.
///
/// The response to use to reply to the request message.
public void Reply(T response)
{
this.responses.Add(response);
}
///
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[EditorBrowsable(EditorBrowsableState.Never)]
public IEnumerator GetEnumerator()
{
return this.responses.GetEnumerator();
}
///
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}