MiscExtension.cs 1.1 KB
Newer Older
麦壳饼's avatar
麦壳饼 已提交
1
using IoTSharp.Data;
2 3
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.WindowsServices;
麦壳饼's avatar
麦壳饼 已提交
4 5 6 7
using Microsoft.AspNetCore.Mvc;
using System;
using System.Diagnostics;
using System.Reflection;
8 9
using System.Runtime.InteropServices;
using System.Text;
麦壳饼's avatar
麦壳饼 已提交
10
using System.Threading.Tasks;
麦壳饼's avatar
麦壳饼 已提交
11

麦壳饼's avatar
麦壳饼 已提交
12
namespace IoTSharp.Extensions
麦壳饼's avatar
麦壳饼 已提交
13 14 15 16 17 18 19
{
    public static class MiscExtension
    {
        public static Task Forget(this Task task)
        {
            return Task.CompletedTask;
        }
麦壳饼's avatar
麦壳饼 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
        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
麦壳饼 已提交
35
      
麦壳饼's avatar
麦壳饼 已提交
36 37
    }
}