public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context.Metadata.ModelType == typeof(String)) return new TrimmingModelBinder(); return null; }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var modelTypeInfo = context.Metadata.ModelType.GetTypeInfo(); if (modelTypeInfo.IsGenericType && modelTypeInfo.GetGenericTypeDefinition().GetTypeInfo() == typeof(KeyValuePair<,>).GetTypeInfo()) { var typeArguments = modelTypeInfo.GenericTypeArguments; var keyMetadata = context.MetadataProvider.GetMetadataForType(typeArguments[0]); var keyBinder = context.CreateBinder(keyMetadata); var valueMetadata = context.MetadataProvider.GetMetadataForType(typeArguments[1]); var valueBinder = context.CreateBinder(valueMetadata); var binderType = typeof(KeyValuePairModelBinder<,>).MakeGenericType(typeArguments); return (IModelBinder)Activator.CreateInstance(binderType, keyBinder, valueBinder); } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context.Metadata.ModelType == typeof(DateTime) || context.Metadata.ModelType == typeof(DateTime?)) { return new AbpDateTimeModelBinder(context.Metadata.ModelType); } return null; }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context.Metadata.ModelType == typeof(HttpRequestMessage)) { return new HttpRequestMessageModelBinder(); } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { var modelTypeTypeInfo = context.Metadata.ModelType.GetTypeInfo(); if (!CustomRepresentationModelInterfaceTypeInfo.IsAssignableFrom(modelTypeTypeInfo)) { return new CustomRepresentationModelBinder(); } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentException(nameof(context)); } if(context.Metadata.ModelType.IsDefined(typeof(ViewModelAttribute), false)) { return new DefaultModelBinder(_documentStore); } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.BindingInfo?.BindingSource?.DisplayName == "FormJson") { return(new FormJsonModelBinder()); } return(null); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { //TODO GETSON remove static string var @interface = context.Metadata .ModelType .GetInterfaces() .FirstOrDefault(i => i.Name.StartsWith("IQuery")); if (@interface != null) { return(new QueryModelBinder()); } return(null); }
/// <summary> /// /// </summary> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(float) || context.Metadata.ModelType == typeof(float?)) { return(new BinderTypeModelBinder(typeof(CurrentCultureFloatBinder))); } return(null); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context.Metadata.IsComplexType && !context.Metadata.IsCollectionType) { var propertyBinders = new Dictionary <ModelMetadata, IModelBinder>(); for (int i = 0; i < context.Metadata.Properties.Count; i++) { var property = context.Metadata.Properties[i]; propertyBinders.Add(property, context.CreateBinder(property)); } return(new TrimModelBinder(propertyBinders)); } return(null); }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (!context.Metadata.IsComplexType) { return(new SimpleTypeModelBinder(context.Metadata.ModelType)); } return(null); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (!context.Metadata.ModelType.IsGenericType || (context.Metadata.ModelType.GetGenericTypeDefinition() != typeof(IRSqlQuery <>) && context.Metadata.ModelType.GetGenericTypeDefinition() != typeof(RSqlQuery <>))) { return(null); } var entityType = context.Metadata.ModelType.GetGenericArguments()[0]; var modelBinderType = typeof(RSqlQueryModelBinder <>).MakeGenericType(entityType); return(new BinderTypeModelBinder(modelBinderType)); }
/// <summary>Gets corresponding model binder from provider context.</summary> /// <param name="context">Model binder provider context instance.</param> /// <returns>Corresponding Model binder.</returns> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (typeof(IRequestHasIdentity <Guid>).IsAssignableFrom(context.Metadata.ModelType)) { return(new GuidIdentityModelBinder(_formatters, _readerFactory)); } if (typeof(IRequestHasIdentity <int>).IsAssignableFrom(context.Metadata.ModelType)) { return(new IntegerIdentityModelBinder(_formatters, _readerFactory)); } return(null); }
/// <summary> /// Returns an <see cref="ActionExecutionModelBinder"/> /// if the bound model derives from <see cref="ActionExecutionModel"/>, else returns null. /// </summary> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (!typeof(ActionExecutionModel).IsAssignableFrom(context.Metadata.ModelType)) { return(null); } return(new ActionExecutionModelBinder(context)); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.IsFlagsEnum) { return(new FlagsEnumBinder()); } return(null); }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(IFormCollection)) { return new FormCollectionModelBinder(); } return null; }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.BindingInfo.BinderType != null) { return new BinderTypeModelBinder(context.BindingInfo.BinderType); } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(decimal)) { return(new DecimalModelBinder()); } return(null); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(string)) { return(new BinderTypeModelBinder(typeof(StringModelBinder))); } return(null); }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(SalesforceNotifications)) { return(new SalesforceNotificationsModelBinder(_bodyModelBinder)); } return(null); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(EntityQueryParameters)) { return(new BinderTypeModelBinder(typeof(EntityQueryParametersModelBinder))); } return(null); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (!context.Metadata.IsComplexType && context.Metadata.ModelType == typeof(DateTime?)) { return(new BinderTypeModelBinder(typeof(NullableDateTimeModelBinder))); } return(null); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.IsComplexType && typeof(IDelta).IsAssignableFrom(context.Metadata.ModelType)) { return(new DeltaModelBinder()); } return(null); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (!context.Metadata.IsComplexType && context.Metadata.ModelType == typeof(string)) // only encode string types { return(new HtmlEncodeModelBinder(new SimpleTypeModelBinder(context.Metadata.ModelType))); } return(null); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(HCaptchaVerifyResponse)) { return(new BinderTypeModelBinder(typeof(HCaptchaModelBinder))); } return(null); }
/// <summary> /// 嘗試取得相應的模型綁定器 /// </summary> /// <param name="context">綁定內容</param> /// <returns>模型綁定器實例</returns> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.IsComplexType) { var propName = context.Metadata.PropertyName; var propInfo = context.Metadata.ContainerType?.GetProperty(propName); var attribute = propInfo ?.GetCustomAttributes(typeof(FromJsonAttribute), false) ?.FirstOrDefault(); // 直接將整個FormData綁定至單一複雜類型的參數上 if (propName != null && propInfo != null && attribute != null) { return(new MultipartJsonModelBinderProvider()); } if (context?.Metadata?.BinderType?.GetCustomAttribute <FromJsonAttribute>() != null) { return(new MultipartJsonModelBinderProvider()); } var visited = context.GetType().GetProperty("Visited", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); ControllerParameterDescriptor cpd = null; foreach (var item in (IEnumerable)visited.GetValue(context)) { var temp = item.GetType().GetProperty("Key").GetValue(item); var tokenField = temp.GetType().GetField("_token", BindingFlags.Instance | BindingFlags.NonPublic); cpd = tokenField.GetValue(temp) as ControllerParameterDescriptor; if (cpd != null) { break; } } if (cpd != null && cpd.ParameterInfo.GetCustomAttribute <FromJsonAttribute>() != null) { return(new MultipartJsonModelBinderProvider()); } } return(null); }
public IModelBinder?GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var modelType = context.Metadata.UnderlyingOrModelType; if (modelType == typeof(byte[])) { return(new PrefixedHexByteArrayModelBinder()); } return(null); }
/// <inheritdoc /> public IModelBinder?GetBinder(ModelBinderProviderContext context) { var nullableType = Nullable.GetUnderlyingType(context.Metadata.ModelType); if (nullableType == null || !nullableType.IsEnum) { // Type isn't nullable or isn't an enum. return(null); } var logger = context.Services.GetRequiredService <ILogger <NullableEnumModelBinder> >(); return(new NullableEnumModelBinder(logger)); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (!context.Metadata.IsComplexType && (context.Metadata.ModelType == typeof(double) || context.Metadata.ModelType == typeof(double?))) { return(new InvariantDecimalModelBinder(context.Metadata.ModelType)); } return(null); }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(Type)) { Invoked = true; } return(null); }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(CheckMarkModelBinder)) { return new CheckMarkModelBinder(); } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(DataTablesParam)) // only encode string types { return(new DataTablesModelBinder()); } return(null); }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(CancellationToken)) { return(new CancellationTokenModelBinder()); } return(null); }
/// <summary> /// 取得ModelBinder /// </summary> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context?.Metadata?.UnderlyingOrModelType == null) return null; if (context.Metadata.UnderlyingOrModelType == typeof(FileNode)) { return new FileNodeModelBinder(); } else if (context.Metadata.UnderlyingOrModelType == typeof(User)) { return new UserModelBinder(); } else if (context.Metadata.UnderlyingOrModelType == typeof(Group)) { return new GroupModelBinder(); } else { return null; } }
public IModelBinder?GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentException(nameof(context)); } if (context.Metadata.ModelType == typeof(Guid)) { return(new Base64GuidModelBinder()); } return(null); }
/// <summary> /// Creates a <see cref="T:Microsoft.AspNetCore.Mvc.ModelBinding.IModelBinder" /> based on <see cref="T:Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderProviderContext" />. /// </summary> /// <param name="context">The <see cref="T:Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderProviderContext" />.</param> /// <returns> /// An <see cref="T:Microsoft.AspNetCore.Mvc.ModelBinding.IModelBinder" />. /// </returns> /// <exception cref="ArgumentNullException">context</exception> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.IsEnumerableType && !context.Metadata.ElementMetadata.IsComplexType) { return(new ArrayModelBinder()); } return(null); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType.FullName.Contains("DynamicFilter")) { return(new BinderTypeModelBinder(typeof(DynamicFilterBinder))); } return(null); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(ProductModel)) { return(new BinderTypeModelBinder(typeof(AuthorEntityBinder))); } return(null); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } //判断当前实例表示的模型类型是否为Student if (context.Metadata.ModelType == typeof(Student)) { return(new BinderTypeModelBinder(typeof(StudentEntityBinder))); } return(null); }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (!context.Metadata.IsComplexType) { return new SimpleTypeModelBinder(context.Metadata.ModelType); } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); var type = context.Metadata.ModelType; if (typeof(IDbConnection).IsAssignableFrom(type) || typeof(IUnitOfWork).IsAssignableFrom(type)) { return ServiceEndpointNullModelBinder.Instance; } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.ModelType == typeof(DateTime) || context.Metadata.ModelType == typeof(DateTime?)) { return(new DateTimeModelBinder(_customFormat, loggerFactory)); } return(null); }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.BindingInfo?.BindingSource != null && context.BindingInfo.BindingSource.CanAcceptDataFrom(BindingSource.Body)) { return new BodyModelBinder(_readerFactory); } return null; }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.BindingInfo.BindingSource != null && context.BindingInfo.BindingSource.CanAcceptDataFrom(BindingSource.Services)) { return new ServicesModelBinder(); } return null; }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var modelType = context.Metadata.ModelType; // Arrays are handled by another binder. if (modelType.IsArray) { return null; } // If the model type is ICollection<> then we can call its Add method, so we can always support it. var collectionType = ClosedGenericMatcher.ExtractGenericInterface(modelType, typeof(ICollection<>)); if (collectionType != null) { var elementType = collectionType.GenericTypeArguments[0]; var elementBinder = context.CreateBinder(context.MetadataProvider.GetMetadataForType(elementType)); var binderType = typeof(CollectionModelBinder<>).MakeGenericType(collectionType.GenericTypeArguments); return (IModelBinder)Activator.CreateInstance(binderType, elementBinder); } // If the model type is IEnumerable<> then we need to know if we can assign a List<> to it, since // that's what we would create. (The cases handled here are IEnumerable<>, IReadOnlyColection<> and // IReadOnlyList<>). // // We need to check IsReadOnly because we need to know if we can SET the property. var enumerableType = ClosedGenericMatcher.ExtractGenericInterface(modelType, typeof(IEnumerable<>)); if (enumerableType != null && !context.Metadata.IsReadOnly) { var listType = typeof(List<>).MakeGenericType(enumerableType.GenericTypeArguments); if (modelType.GetTypeInfo().IsAssignableFrom(listType.GetTypeInfo())) { var elementType = enumerableType.GenericTypeArguments[0]; var elementBinder = context.CreateBinder(context.MetadataProvider.GetMetadataForType(elementType)); var binderType = typeof(CollectionModelBinder<>).MakeGenericType(enumerableType.GenericTypeArguments); return (IModelBinder)Activator.CreateInstance(binderType, elementBinder); } } return null; }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var modelType = context.Metadata.ModelType; if (modelType == typeof(IFormFile) || modelType == typeof(IFormFileCollection) || typeof(IEnumerable<IFormFile>).GetTypeInfo().IsAssignableFrom(modelType.GetTypeInfo())) { return new FormFileModelBinder(); } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); if (!context.Metadata.IsComplexType) { // Look for scrubber attributes var propName = context.Metadata.PropertyName; var propInfo = context.Metadata.ContainerType.GetProperty(propName); // Only one scrubber attribute can be applied to each property var attribute = propInfo.GetCustomAttributes(typeof(IScrubberAttribute), false).FirstOrDefault(); if (attribute != null) return new ScrubbingModelBinder(context.Metadata.ModelType, attribute as IScrubberAttribute); } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); if (!context.Metadata.IsComplexType && !string.IsNullOrEmpty(context.Metadata.PropertyName)) { // Look for DateTimeOffset attributes var propName = context.Metadata.PropertyName; var propInfo = context.Metadata.ContainerType.GetProperty(propName); // Only one scrubber attribute can be applied to each property var attribute = propInfo.GetCustomAttributes(typeof(AdjustToTimezoneAttribute), false).FirstOrDefault() as AdjustToTimezoneAttribute; if (attribute != null) return new AdjustToTimeZoneModelBinder(context.Metadata.ModelType, attribute.TimeZoneIdPropertyName); } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (!context.Metadata.IsComplexType) { Type type = context.Metadata.ModelType; if (type == typeof(decimal) || type == typeof(decimal?)) { return new ConvertModelBinder(); } } return null; }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Metadata.IsComplexType && !context.Metadata.IsCollectionType) { var propertyBinders = new Dictionary<ModelMetadata, IModelBinder>(); foreach (var property in context.Metadata.Properties) { propertyBinders.Add(property, context.CreateBinder(property)); } return new ComplexTypeModelBinder(propertyBinders); } return null; }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.BindingInfo.BindingSource != null && context.BindingInfo.BindingSource.CanAcceptDataFrom(BindingSource.Header)) { // We only support strings and collections of strings. Some cases can fail // at runtime due to collections we can't modify. if (context.Metadata.ModelType == typeof(string) || context.Metadata.ElementType == typeof(string)) { return new HeaderModelBinder(); } } return null; }
/// <inheritdoc /> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var modelType = context.Metadata.ModelType; var dictionaryType = ClosedGenericMatcher.ExtractGenericInterface(modelType, typeof(IDictionary<,>)); if (dictionaryType != null) { var keyType = dictionaryType.GenericTypeArguments[0]; var keyBinder = context.CreateBinder(context.MetadataProvider.GetMetadataForType(keyType)); var valueType = dictionaryType.GenericTypeArguments[1]; var valueBinder = context.CreateBinder(context.MetadataProvider.GetMetadataForType(valueType)); var binderType = typeof(DictionaryModelBinder<,>).MakeGenericType(dictionaryType.GenericTypeArguments); return (IModelBinder)Activator.CreateInstance(binderType, keyBinder, valueBinder); } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context.Metadata.IsComplexType) { var propertyBinders = new Dictionary<ModelMetadata, IModelBinder>(); foreach (var property in context.Metadata.Properties) { propertyBinders.Add(property, context.CreateBinder(property)); } return new TestableComplexTypeModelBinder(propertyBinders); } return null; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { var binder = _factory(context); if (binder != null) { SuccessCount++; } return binder; }
public IModelBinder GetBinder(ModelBinderProviderContext context) { var allowedBindingSource = context.BindingInfo.BindingSource; if (allowedBindingSource?.CanAcceptDataFrom(BindAddressAttribute.Source) == true) { // Binding Sources are opt-in. This model either didn't specify one or specified something // incompatible so let other binders run. return new AddressBinder(); } return null; }
/// <summary> /// Uses a DateTimeModelProvider for dates. /// </summary> public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context.Metadata.ModelType != typeof(DateTime) && context.Metadata.ModelType != typeof(DateTime?)) { return null; } return new DateTimeModelBinder(_timeZoneProvider); }
/// <summary> /// Returns the model binder for a question. /// </summary> public IModelBinder GetBinder(ModelBinderProviderContext context) { var modelType = context.Metadata.ModelType; if (!_baseTypes.Contains(modelType)) return null; var derivedModelBinders = _subTypes[modelType].ToDictionary ( t => t, t => context.CreateBinder ( context.MetadataProvider.GetMetadataForType(t) ) ); return new AbstractModelBinder(modelType, derivedModelBinders, context.MetadataProvider); }