using System;
using System.Collections.ObjectModel;
using System.Linq;
namespace OpenTap
{
///
/// Read-only collection of parameters where parameters can be looked up by name.
///
class ParameterCollection : ReadOnlyCollection, IParameters
{
IParameter GetParameterByObjectType(string name) => this.FirstOrDefault(x => x.ObjectType == name);
IParameter GetParameter(string name) => this.FirstOrDefault(x => x.Name == name);
/// Gets a parameter by name.
///
public IConvertible this[string name] => (GetParameterByObjectType(name) ?? GetParameter(name))?.Value;
/// Creates a new parameter collection from an existing list of parameters.
public ParameterCollection(IParameter[] list) : base(list)
{
}
internal static readonly ParameterCollection Empty = new ParameterCollection(Array.Empty());
}
}