Search code examples
c#asp.net-mvcmyob

How to pass function Parameter when calling below function from other method in c#


Function wants to call from another Method.

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

Tried with the below code. How I can get return value from onComplete and onError function.?

Calling Above method from other code.

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

Success Method:

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

Error Method

public Exception SInvoiceUpdateError(Uri foUri)
        {
            Exception ex = new Exception();
            return ex;
        }

Solution

  • OnError and OnComplete are Actions which are some pre rolled delegates provided by the BCL. By their very definition they don't return a value that's the signature of an Action. Action (and the ones with more generic args just describe something that takes arguments but still returns void. If you control the interface of the update method, change them to Func and then you can have them return something