| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using Microsoft.AspNetCore.Mvc;
- namespace Masuit.Tools.AspNetCore.ModelBinder
- {
- /// <summary>
- /// 自动装配声明参数值
- /// <list type="bullet">
- /// <item>
- /// 布尔
- /// <description>bool</description>
- /// </item>
- /// <item>
- /// 字符/字符串
- /// <description>char/string</description>
- /// </item>
- /// <item>
- /// 浮点型
- /// <description>float/double/decimal</description>
- /// </item>
- /// <item>
- /// 整型
- /// <description>byte/sbyte/short/ushort/int/uint/long/ulong</description>
- /// </item>
- /// <item>
- /// 枚举
- /// <description>Enum</description>
- /// </item>
- /// <item>
- /// 其他类型
- /// <description>JObject/XDocument/Uri/Guid/TimeSpan</description>
- /// </item>
- /// </list>
- /// </summary>
- [AttributeUsage(AttributeTargets.Parameter)]
- public class FromBodyOrDefaultAttribute : ModelBinderAttribute
- {
- public FromBodyOrDefaultAttribute() : this(BindType.Default, null, null)
- {
- }
- public FromBodyOrDefaultAttribute(IConvertible defaultValue) : this(BindType.Default, null, defaultValue)
- {
- }
- public FromBodyOrDefaultAttribute(BindType type) : this(type, null, null)
- {
- }
- public FromBodyOrDefaultAttribute(BindType type, string fieldname) : this(type, fieldname, null)
- {
- }
- public FromBodyOrDefaultAttribute(BindType type, string fieldname, IConvertible defaultValue) : base(typeof(FromBodyOrDefaultModelBinder))
- {
- Type = type;
- FieldName = fieldname;
- DefaultValue = defaultValue;
- }
- public string FieldName { get; set; }
- public IConvertible DefaultValue { get; set; }
- /// <summary>
- /// 取值方式
- /// </summary>
- public BindType Type { get; set; }
- }
- }
|