async PluginFunction
This commit is contained in:
@@ -34,7 +34,7 @@ public abstract class PluginFunction : PluginFeature
|
||||
|
||||
public virtual object? Execute(PluginFunctionParameter? @params)
|
||||
{
|
||||
object? result = default;
|
||||
object? result = null;
|
||||
|
||||
if (OnPreExecute(@params, ref result))
|
||||
result = ExecuteFunction(@params);
|
||||
@@ -43,6 +43,48 @@ public abstract class PluginFunction : PluginFeature
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual Task<object?> ExecuteAsync()
|
||||
{
|
||||
return ExecuteAsync((PluginFunctionParameter?)null);
|
||||
}
|
||||
|
||||
protected abstract object? ExecuteFunction(PluginFunctionParameter? @params);
|
||||
public virtual Task<T?> ExecuteAsync<T>(params object?[]? @params)
|
||||
{
|
||||
return ExecuteAsync<T>(new PluginFunctionSimpleParamter(@params));
|
||||
}
|
||||
|
||||
public virtual Task<object?> ExecuteAsync(params object?[]? @params)
|
||||
{
|
||||
return ExecuteAsync(new PluginFunctionSimpleParamter(@params));
|
||||
}
|
||||
|
||||
public virtual async Task<T?> ExecuteAsync<T>(PluginFunctionSimpleParamter? @params)
|
||||
{
|
||||
if (await ExecuteAsync(@params) is T result)
|
||||
return result;
|
||||
return default;
|
||||
}
|
||||
|
||||
public virtual async Task<object?> ExecuteAsync(PluginFunctionParameter? @params)
|
||||
{
|
||||
object? result = null;
|
||||
|
||||
if (OnPreExecute(@params, ref result))
|
||||
result = await ExecuteFunctionAsync(@params);
|
||||
|
||||
OnPostExecute(@params, ref result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected virtual object? ExecuteFunction(PluginFunctionParameter? @params)
|
||||
{
|
||||
return ExecuteFunctionAsync(@params).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
protected virtual Task<object?> ExecuteFunctionAsync(PluginFunctionParameter? @params)
|
||||
{
|
||||
return Task.FromResult(ExecuteFunction(@params));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user