You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.3 KiB
62 lines
1.3 KiB
using System.Data;
|
|
|
|
namespace Connected.ServiceModel.Client.Data;
|
|
internal sealed class DataParameterCollection : List<IDbDataParameter>, 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);
|
|
}
|
|
}
|