在c#中,当从其他方法调用以下函数时,如何传递函数Parameter?

问题描述 投票:0回答:1

函数想从另一个方法调用。

public virtual void Update(CompanyFile cf, T entity, ICompanyFileCredentials credentials, Action<HttpStatusCode, string> onComplete, Action<Uri, Exception> onError, ErrorLevel errorLevel = ErrorLevel.IgnoreWarnings);

试着用下面的代码。如何从onComplete和onError函数中获取返回值?

从其他代码中调用上述方法。

loServiceInvoiceSvc.Update(msCompanyFile, serviceInvoice, msCompanyFileCredentials,SInvoiceUpdateSuccess, SInvoiceUpdateError);

成功方法。

public string SInvoiceUpdateSuccess(HttpStatusCode foStatus)
    {
        return "1";
    }

错误方法

public Exception SInvoiceUpdateError(Uri foUri)
        {
            Exception ex = new Exception();
            return ex;
        }
c# asp.net-mvc myob
1个回答
0
投票

OnError和OnComplete是由BCL提供的一些预滚动委托的Action。从它们的定义来看,它们不会返回一个Action的签名的值。Action(还有那些更通用的args只是描述一些接受参数但仍然返回void的东西。如果你控制了update方法的接口,把它们改成Func,然后你就可以让它们返回一些东西了

© www.soinside.com 2019 - 2024. All rights reserved.