简体   繁体   中英

Passing a class type as a parameter to a process in an external dll reference in C#

I have the following code that errors on passing the 'stockReportParameters' in the call to the process in an external DLL:

{
        String accessToken = Helper.BearerToken(this.Url.Request.Headers.Authorization.ToString());

        return await this.InventoryClient.GetStoreLevelReportAsync(accessToken, stockReportParameters, cancellationToken);

There is both a local and remote public class 'stockReportParameters' both defined as

    public class StockReportParameters
{ public List<Guid> Stores { get; set; } }

The error is:

Argument 2: Cannot convert from {the local class} to {the remote class}

Argument Type {the local class} is not assignable to parameter type {the remote class}

How do I pass the contents of this to the remote process?

"GetStoreLevelReportAsync" expects a parameter of type "{the remote class}" as you call it but "stockReportParameters" is of type "{the local class}". You can't just assign one to the other so you either have to change "stockReportParameters" to be of the type "{the remote class}" or use a new variable of type "{the remote class}" and copy the values of "stockReportParameters":

var remoteStockReportParameters = new [Insert "{the remote class here}"]();
remoteStockReportParameters.Stores = new List<Guid>(stockReportParameters.Stores);
return await this.InventoryClient.GetStoreLevelReportAsync(accessToken, remoteStockReportParameters, cancellationToken);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM