mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-19 01:31:17 -10:00
Adding reference source for System.Data System.Data.DataSetExtensions System.Data.Entity System.Data.Entity.Design System.Data.Linq System.Data.SqlXml System.ServiceModel System.ServiceModel.Activation System.ServiceModel.Activities System.ServiceModel.Channels System.ServiceModel.Discovery System.ServiceModel.Internals System.ServiceModel.Routing System.ServiceModel.WasHosting System.ServiceModel.Web System.Web System.Web.ApplicationServices System.Web.DynamicData System.Web.Entity System.Web.Entity.Design System.Web.Extensions System.Web.Mobile System.Web.Routing System.Web.Services System.Xml System.Xml.Linq
50 lines
2.2 KiB
C#
50 lines
2.2 KiB
C#
namespace System.Web.ModelBinding {
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
|
|
public abstract class AssociatedValidatorProvider : ModelValidatorProvider {
|
|
protected virtual ICustomTypeDescriptor GetTypeDescriptor(Type type) {
|
|
return TypeDescriptorHelper.Get(type);
|
|
}
|
|
|
|
public override sealed IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ModelBindingExecutionContext context) {
|
|
if (metadata == null) {
|
|
throw new ArgumentNullException("metadata");
|
|
}
|
|
if (context == null) {
|
|
throw new ArgumentNullException("context");
|
|
}
|
|
|
|
if (metadata.ContainerType != null && !String.IsNullOrEmpty(metadata.PropertyName)) {
|
|
return GetValidatorsForProperty(metadata, context);
|
|
}
|
|
|
|
return GetValidatorsForType(metadata, context);
|
|
}
|
|
|
|
protected abstract IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ModelBindingExecutionContext context, IEnumerable<Attribute> attributes);
|
|
|
|
private IEnumerable<ModelValidator> GetValidatorsForProperty(ModelMetadata metadata, ModelBindingExecutionContext context) {
|
|
ICustomTypeDescriptor typeDescriptor = GetTypeDescriptor(metadata.ContainerType);
|
|
PropertyDescriptor property = typeDescriptor.GetProperties().Find(metadata.PropertyName, true);
|
|
if (property == null) {
|
|
throw new ArgumentException(
|
|
String.Format(
|
|
CultureInfo.CurrentCulture,
|
|
SR.GetString(SR.Common_PropertyNotFound),
|
|
metadata.ContainerType.FullName, metadata.PropertyName),
|
|
"metadata");
|
|
}
|
|
|
|
return GetValidators(metadata, context, property.Attributes.OfType<Attribute>());
|
|
}
|
|
|
|
private IEnumerable<ModelValidator> GetValidatorsForType(ModelMetadata metadata, ModelBindingExecutionContext context) {
|
|
return GetValidators(metadata, context, GetTypeDescriptor(metadata.ModelType).GetAttributes().Cast<Attribute>());
|
|
}
|
|
}
|
|
}
|