using System.Data; namespace Connected.ServiceModel.Client.Data; internal sealed class DataParameterCollection : List, IDataParameterCollection { public object this[string parameterName] { get { foreach (var parameter in this) { if (string.Equals(parameter.ParameterName, parameterName, StringComparison.OrdinalIgnoreCase)) return parameter; } throw new NullReferenceException(nameof(IDbDataParameter)); } set { if (value is not IDbDataParameter parameter) throw new InvalidCastException(nameof(IDbDataParameter)); var idx = IndexOf(parameterName); if (idx < 0) throw new NullReferenceException(nameof(IDbDataParameter)); this[idx] = parameter; } } public bool Contains(string parameterName) { foreach (var parameter in this) { if (string.Equals(parameter.ParameterName, parameterName, StringComparison.OrdinalIgnoreCase)) return true; } return false; } public int IndexOf(string parameterName) { for (var i = 0; i < Count; i++) { var current = this[i]; if (string.Equals(current.ParameterName, parameterName, StringComparison.OrdinalIgnoreCase)) return i; } return -1; } public void RemoveAt(string parameterName) { if (this[parameterName] is IDbDataParameter target) Remove(target); } }