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