如何在另一个引用的程序集中使用与另一个类型同名的类型?

How do I use a type with the same name of another type in another referenced assembly?

我有一个荒谬的情况(不要怪我,它是第三方软件)我需要两个引用(Erp.Contracts.BO.Quote 和 Erp.Contracts.BO.SalesOrder),但是类型 Erp.Tablesets.QuoteQtyRow 在两个程序集中都有定义!

如何在代码中使用它们?

void Absurdity()
{
    Erp.Tablesets.QuoteQtyRow qqr_Quote = null; //<-- my intention is to use the one from the quote assembly here.
    Erp.Tablesets.QuoteQtyRow qqr_SO = null; //<-- my intention is to use the one from the sales order assembly here.
}

编译器抛出错误。即:"The type 'Erp.Tablesets.QuoteQtyRow' exists in both assemblies."

编辑:限制:

  1. 我没有使用此答案中提供的外部别名的灵活性 Class with same name in two assemblies (intentionally)。我受限于第三方软件提供的环境。我本质上需要一种方法来在方法体内进行区分。

  2. 我知道我可以通过使用 dynamic 关键字完全避免这个问题,但我正在寻找一个可能的强类型解决方案。

  3. 可能没有解决办法,但我想在我放弃之前用尽我所有的资源。

Epicor ERP 使用一种工具将来自数据库的 table 组合成数据集,然后再放入业务对象中。此业务对象在契约程序集中进行了描述,但是正如您所发现的,当您使用引用相同 table 的两个业务对象时,您会 运行 陷入问题。这更常见于 SerialNumber tables.

我从您的注释中了解到,您在 Epicor ERP 应用程序中的方法指令或数据指令中提供了方法主体代码。这是在客户端输入并存储在数据库中,但在 Deployment\Server\BPM\Sources\BO 文件夹中的服务器上生成代码并编译到 Deployment\Server\Customization\BO 文件夹中。

无法在 BPM 设计器的 "Execute Custom Code" 工作流项中为引用的 DLL 指定别名。在 SCR 148549 中请求修复。没有供您编辑的项目文件,即使每次启用和禁用 BPM,它也会重新生成。

但是,如果您使用 "Invoke External Method" 工作流程项,那么您可以构建自己的 dll 并将其放在 Deployment\Server\Customization\Externals 文件夹中。为此:

  • 在 BPM 的方法指令维护中单击操作 > 为您的方法创建编程接口并复制代码。
  • 在 Visual Studio
  • 中创建一个新的 Class 库项目
  • 将复制的代码粘贴到 .cs 文件中
  • 添加程序集 - 框架参考:
    • System.Data.Entity
    • System.ServiceModel
    • System.Transactions
  • 将文件引用添加到
    • Bin\Epicor.ServiceModel.dll
    • Assemblies\Epicor.Ice.dll
    • Assemblies\Epicor.System.dll
    • Assemblies\Ice.Data.Model.dll
    • Assemblies\Erp.数据.910100.dll
  • 并为 BPM 的 BO 添加参考,即
    • Assemblies\Erp.Contracts.BO.Quote.dll
  • 确保所有引用都将“复制本地”设置为 false。
  • 继承自Ice.ContextBoundBase<Erp.ErpContext>
  • 添加一个接受上下文的构造函数public MyQuote (Erp.ErpContext ctx) : base(ctx){ }

您不能完全复制并粘贴 "Execute Custom Code" 正文,因为您将无法访问 tt 行变量,这些都在 ds 中。