我收到以下错误:Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
public void LogClientSideErrors(string message, ValidationType validationType)
=> validationType switch
{
ValidationType.Success => setInfo(message, controllerInfo),
ValidationType.Critical => setFatal(message, controllerInfo),
ValidationType.Error => setError(message, controllerInfo),
ValidationType.Exception => setError(message, controllerInfo),
ValidationType.Information => setInfo(message, controllerInfo),
ValidationType.Warning => setWarn(message, controllerInfo),
_ => setError("invalid enum value", controllerInfo),
};
更新:工作解决方案:
internal static void GenerateLogs(string message, string controllerInfo, ValidationType validationType)
=> (validationType switch
{
var x when x == ValidationType.Success || x == ValidationType.Information => new Action<string, string>(setInfo),
ValidationType.Critical => setFatal,
var x when x == ValidationType.Error || x == ValidationType.Exception => setError,
ValidationType.Warning => setWarn,
_ => (_, controllerInfo) => setError("invalid enum value", controllerInfo),
})(message, controllerInfo);