MiscExtension.cs 965 字节
Newer Older
麦壳饼's avatar
麦壳饼 已提交
1
using IoTSharp.Data;
麦壳饼's avatar
麦壳饼 已提交
2 3 4 5 6
using Microsoft.AspNetCore.Mvc;
using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;
麦壳饼's avatar
麦壳饼 已提交
7

麦壳饼's avatar
麦壳饼 已提交
8
namespace IoTSharp.Extensions
麦壳饼's avatar
麦壳饼 已提交
9 10 11 12 13 14 15
{
    public static class MiscExtension
    {
        public static Task Forget(this Task task)
        {
            return Task.CompletedTask;
        }
麦壳饼's avatar
麦壳饼 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
        public static BadRequestObjectResult ExceptionRequest( this ControllerBase @base,Exception exception)
        {
            MethodBase mb = new StackTrace(exception).GetFrame(0).GetMethod();
            MethodBase cu = new StackTrace(true).GetFrame(0).GetMethod();
            return @base.BadRequest(new
            {
                code = ApiCode.Exception,
                msg = exception.Message,
                data = new
                {
                    ExceptionMethod = mb.DeclaringType.FullName + "." + mb.Name,
                    MethodName = cu.Name
                }
            });
        }
麦壳饼's avatar
麦壳饼 已提交
31 32
    }
}