using NCC.Dependency;
using NCC.Extensions;
using NCC.UnifyResult;
using Microsoft.AspNetCore.Http;
using System;
namespace Microsoft.AspNetCore.Mvc
{
///
/// 规范化结果配置
///
[SuppressSniffer, AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class UnifyResultAttribute : ProducesResponseTypeAttribute
{
///
/// 构造函数
///
///
public UnifyResultAttribute(int statusCode) : base(statusCode)
{
}
///
/// 构造函数
///
///
public UnifyResultAttribute(Type type) : base(type, StatusCodes.Status200OK)
{
WrapType(type);
}
///
/// 构造函数
///
///
///
public UnifyResultAttribute(Type type, int statusCode) : base(type, statusCode)
{
WrapType(type);
}
///
/// 包装类型
///
///
private void WrapType(Type type)
{
if (type != null)
{
if (!type.HasImplementedRawGeneric(UnifyContext.RESTfulResultType))
{
Type = UnifyContext.RESTfulResultType.MakeGenericType(type);
}
else Type = default;
}
}
}
}