linux-packaging-mono/mcs/class/System.Web.Mvc3/Mvc/ModelValidatorProviderCollection.cs
Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

52 lines
1.9 KiB
C#

namespace System.Web.Mvc {
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
public class ModelValidatorProviderCollection : Collection<ModelValidatorProvider> {
private IResolver<IEnumerable<ModelValidatorProvider>> _serviceResolver;
public ModelValidatorProviderCollection() {
_serviceResolver = new MultiServiceResolver<ModelValidatorProvider>(() => Items);
}
public ModelValidatorProviderCollection(IList<ModelValidatorProvider> list)
: base(list) {
_serviceResolver = new MultiServiceResolver<ModelValidatorProvider>(() => Items);
}
internal ModelValidatorProviderCollection(IResolver<IEnumerable<ModelValidatorProvider>> serviceResolver, params ModelValidatorProvider[] validatorProvidors)
: base(validatorProvidors) {
_serviceResolver = serviceResolver ?? new MultiServiceResolver<ModelValidatorProvider>(
()=>Items
);
}
private IEnumerable<ModelValidatorProvider> CombinedItems {
get {
return _serviceResolver.Current;
}
}
protected override void InsertItem(int index, ModelValidatorProvider item) {
if (item == null) {
throw new ArgumentNullException("item");
}
base.InsertItem(index, item);
}
protected override void SetItem(int index, ModelValidatorProvider item) {
if (item == null) {
throw new ArgumentNullException("item");
}
base.SetItem(index, item);
}
public IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context) {
return CombinedItems.SelectMany(provider => provider.GetValidators(metadata, context));
}
}
}