在 C# 中将类类型作为参数传递给外部 dll 引用中的进程

本文关键字:外部 dll 进程 参数传递 引用 类型 | 更新日期: 2023-09-27 18:32:50

我有以下代码,在调用外部DLL中的进程时传递"stockReportParameters"时出错:

{
        String accessToken = Helper.BearerToken(this.Url.Request.Headers.Authorization.ToString());
        return await this.InventoryClient.GetStoreLevelReportAsync(accessToken, stockReportParameters, cancellationToken);

有一个本地和远程公共类"stockReportParameters",两者都定义为

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

错误是:

参数 2:无法从 {本地类} 转换为 {远程 类}

参数类型 {本地类} 不可分配给参数类型 {远程类}

如何将此内容传递给远程进程?

在 C# 中将类类型作为参数传递给外部 dll 引用中的进程

"GetStoreLevelReportAsync" 需要一个类型为"{the remote class}"的参数,但"stockReportParameters"的类型为"{本地类}"。您不能只将一个分配给另一个,因此您必须将"stockReportParameters"更改为"{远程类}"类型,或者使用类型为"{远程类}"的新变量并复制"stockReportParameters"的值:

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