iotgateway/WalkingTec.Mvvm/WalkingTec.Mvvm.Mvc/Binders/StringBinderProvider.cs
2021-12-14 14:10:44 +08:00

37 lines
1.0 KiB
C#

using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using System;
using System.Collections;
using WalkingTec.Mvvm.Core;
namespace WalkingTec.Mvvm.Mvc.Binders
{
/// <summary>
/// CustomBinderProvider
/// </summary>
public class StringBinderProvider : IModelBinderProvider
{
/// <summary>
/// GetBinder
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public IModelBinder GetBinder(ModelBinderProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (context.Metadata.ModelType == typeof(DateRange))
return new BinderTypeModelBinder(typeof(DateRangeBinder));
if (context.Metadata.ModelType == typeof(string))
{
return new BinderTypeModelBinder(typeof(StringIgnoreLTGTBinder));
}
return null;
}
}
}