Skip to content

Class ApiOut

Namespace: Tool.Web.Api
Assembly: Tool.Net.dll

系统默认 Api输出结果 抽象类,用于普通返回值,特殊返回值建议您自己实现。

csharp
public abstract class ApiOut : IApiOut

Inheritance

objectApiOut

Derived

FileOut, JsonOut, RedirectOut, ViewOut, WriteOut

Implements

IApiOut

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Extension Methods

ObjectExtension.Add<T>(object, object, object), ObjectExtension.CopyEntity(object, object, params string[]), ObjectExtension.EntityToJson(object), ObjectExtension.EntityToJson(object, bool), ObjectExtension.EntityToJson(object, bool, string), DictionaryExtension.GetDictionary(object), TypeExtension.GetFieldKey(object, string, out bool), TypeExtension.GetFieldKey<T>(object, string, out bool), TypeExtension.GetFieldKey(object, Type, string, out bool), ObjectExtension.GetIntPtr(object), ObjectExtension.GetIntPtrInt(object), TypeExtension.GetPropertieFind(object, string, bool), TypeExtension.GetProperties(object), TypeExtension.GetPropertyKey(object, string, out bool), TypeExtension.GetPropertyKey<T>(object, string, out bool), TypeExtension.GetPropertyKey(object, Type, string, out bool), TypeExtension.GetValue(object, PropertyDescriptor), TypeExtension.GetValue(object, string, bool), TypeExtension.GetValue(object, string), ObjectExtension.Read<T>(object, object, int, int), ObjectExtension.Read<T>(object, int, object, int, int), DictionaryExtension.SetDictionary(object, IDictionary<string, object>), TypeExtension.SetFieldKey(object, string, object), TypeExtension.SetFieldKey<T>(object, string, object), TypeExtension.SetFieldKey(object, Type, string, object), TypeExtension.SetPropertyKey(object, string, object), TypeExtension.SetPropertyKey<T>(object, string, object), TypeExtension.SetPropertyKey(object, Type, string, object), TypeExtension.SetValue(object, PropertyDescriptor, object), TypeExtension.SetValue(object, string, object, bool), TypeExtension.SetValue(object, string, object), ObjectExtension.ToBase64String(object), ObjectExtension.ToBytes(object), ObjectExtension.ToBytes(object, out Type), DictionaryExtension.ToDictionary(object), DictionaryExtension.ToDictionary<T>(object), DictionaryExtension.ToIDictionary(object), DictionaryExtension.ToIDictionary<T>(object), ObjectExtension.ToJson(object), ObjectExtension.ToJson(object, JsonSerializerOptions), ObjectExtension.ToJsonWeb(object), ObjectExtension.ToJsonWeb(object, Action<JsonSerializerOptions>), ObjectExtension.ToTryVar<T>(object, T), ObjectExtension.ToVar<T>(object), ObjectExtension.ToVar(object, Type, bool), ObjectExtension.ToVar(object, string), ObjectExtension.ToXml(object)

Remarks

代码由逆血提供支持

Constructors

ApiOut()

无参构造

csharp
protected ApiOut()

Properties

ContentType

输出类型

csharp
public abstract string ContentType { get; set; }

Property Value

string

StatusCode

HTTP 返回 Code

csharp
public abstract int StatusCode { get; set; }

Property Value

int

Methods

EventStream(Func<EventStream, Task>, int)

SSE服务器事件流

csharp
public static EventStreamOut EventStream(Func<EventStream, Task> func, int retry = 3000)

Parameters

func Func<EventStream, Task>

流任务

retry int

超时重连时间

Returns

EventStreamOut

输出对象

EventStreamAsync(Func<EventStream, Task>, int)

SSE服务器事件流

csharp
public static Task<EventStreamOut> EventStreamAsync(Func<EventStream, Task> func, int retry = 3000)

Parameters

func Func<EventStream, Task>

流任务

retry int

超时重连时间

Returns

Task<EventStreamOut>

输出对象

ExecuteOutAsync(AshxRouteData)

系统回调,用于完成该请求任务的输出

csharp
public abstract Task ExecuteOutAsync(AshxRouteData ashxRoute)

Parameters

ashxRoute AshxRouteData

包含所有有效信息

Returns

Task

异步任务

File(string, Stream)

向客户端返回下载的资源文件

csharp
public static FileOut File(string name, Stream fileStream)

Parameters

name string

文件名称

fileStream Stream

文件流对象

Returns

FileOut

输出对象

File(string, byte[])

向客户端返回下载的资源文件

csharp
public static FileOut File(string name, byte[] bytes)

Parameters

name string

文件名称

bytes byte[]

文件字节流

Returns

FileOut

输出对象

FileAsync(string, Stream)

异步向客户端返回下载的资源文件

csharp
public static Task<FileOut> FileAsync(string name, Stream fileStream)

Parameters

name string

文件名称

fileStream Stream

文件流对象

Returns

Task<FileOut>

输出对象

FileAsync(string, byte[])

异步向客户端返回下载的资源文件

csharp
public static Task<FileOut> FileAsync(string name, byte[] bytes)

Parameters

name string

文件名称

bytes byte[]

文件字节流

Returns

Task<FileOut>

输出对象

Json(object)

向客户端返回JSON数据

csharp
public static JsonOut Json(object obj)

Parameters

obj object

源数据

Returns

JsonOut

输出对象

Json(object, JsonSerializerOptions)

向客户端返回JSON数据

csharp
public static JsonOut Json(object obj, JsonSerializerOptions JsonOptions)

Parameters

obj object

源数据

JsonOptions JsonSerializerOptions

Json 转换条件

Returns

JsonOut

输出对象

JsonAsync(object)

异步向客户端返回JSON数据

csharp
public static Task<JsonOut> JsonAsync(object obj)

Parameters

obj object

源数据

Returns

Task<JsonOut>

输出对象

JsonAsync(object, JsonSerializerOptions)

异步向客户端返回JSON数据

csharp
public static Task<JsonOut> JsonAsync(object obj, JsonSerializerOptions JsonOptions)

Parameters

obj object

源数据

JsonOptions JsonSerializerOptions

Json 转换条件

Returns

Task<JsonOut>

输出对象

NoContent()

无输出结果

csharp
public static NoContentOut NoContent()

Returns

NoContentOut

输出对象

NoContentAsync()

无输出结果

csharp
public static Task<NoContentOut> NoContentAsync()

Returns

Task<NoContentOut>

输出对象

PathView(string)

向客户端返回页面

csharp
public static ViewOut PathView(string pathName)

Parameters

pathName string

源数据(是wwwroot文件夹下面的相对路径),不支持绝对路径 的文件夹名称 支持多重文件 不能包含文件

Returns

ViewOut

输出对象

PathViewAsync(string)

异步向客户端返回页面

csharp
public static Task<ViewOut> PathViewAsync(string pathName)

Parameters

pathName string

源数据(是wwwroot文件夹下面的相对路径),不支持绝对路径 的文件夹名称 支持多重文件 不能包含文件

Returns

Task<ViewOut>

输出对象

Redirect(string)

向客户端返回重定向的URl

csharp
public static RedirectOut Redirect(string url)

Parameters

url string

跳转的URL

Returns

RedirectOut

输出对象

RedirectAsync(string)

异步向客户端返回重定向的URl

csharp
public static Task<RedirectOut> RedirectAsync(string url)

Parameters

url string

跳转的URL

Returns

Task<RedirectOut>

输出对象

View()

向客户端返回页面(默认模式路径:wwwroot文件夹下,加上控制器名和接口名:/Views/Api/Get.html)

csharp
public static ViewOut View()

Returns

ViewOut

输出对象

View(string)

向客户端返回页面

csharp
public static ViewOut View(string viewName)

Parameters

viewName string

源数据(是wwwroot文件夹下面的相对路径),不支持绝对路径

Returns

ViewOut

输出对象

ViewAsync()

异步向客户端返回页面(默认模式路径:ApiView文件夹下,加上控制器名和接口名:/Views/Api/Get.html)

csharp
public static Task<ViewOut> ViewAsync()

Returns

Task<ViewOut>

输出对象

ViewAsync(string)

异步向客户端返回页面

csharp
public static Task<ViewOut> ViewAsync(string viewName)

Parameters

viewName string

源数据(是wwwroot文件夹下面的相对路径),不支持绝对路径

Returns

Task<ViewOut>

输出对象

Write(object)

向客户端返回Text数据

csharp
public static WriteOut Write(object obj)

Parameters

obj object

源数据

Returns

WriteOut

输出对象

WriteAsync(object)

异步向客户端返回Text数据

csharp
public static Task<WriteOut> WriteAsync(object obj)

Parameters

obj object

源数据

Returns

Task<WriteOut>

输出对象

基于Apache-2.0协议开源