// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
///
/// Represents a collection of model binder providers.
///
public class ModelBinderProviderCollection : Collection
{
///
/// Initializes a new instance of the class that is empty.
///
public ModelBinderProviderCollection()
{
}
///
/// Initializes a new instance of the class
/// as a wrapper for the specified list.
///
/// The list that is wrapped by the new collection.
public ModelBinderProviderCollection(IList modelBinderProviders)
: base(modelBinderProviders)
{
}
///
/// Removes all model binder providers of the specified type.
///
/// The type to remove.
public void RemoveType() where TModelBinderProvider : IModelBinderProvider
{
RemoveType(typeof(TModelBinderProvider));
}
///
/// Removes all model binder providers of the specified type.
///
/// The type to remove.
public void RemoveType(Type modelBinderProviderType)
{
for (var i = Count - 1; i >= 0; i--)
{
var modelBinderProvider = this[i];
if (modelBinderProvider.GetType() == modelBinderProviderType)
{
RemoveAt(i);
}
}
}
}
}