简体   繁体   English

在直接引用其他dll的其他dll中调用方法会在原始调用中导致引用错误

[英]Calling a method in a different dll that directly references other dlls causes reference error in the originating call

Call in my application 致电我的申请

Essentials.Class.LoadProgressIndicater(parent)

Direct method fails 直接方法失败

LoadProgressIndicater(object parent)
{
    var temp = parent as XtraForm; //XtraForm third party control/dll
}

Indirect method works 间接方法有效

LoadProgressIndicater(object parent)
{
    _LoadProgressIndicater(parent);
}

_LoadProgressIndicater(object parent)
{
    var temp = parent as XtraForm; //XtraForm third party control/dll
}

Why does this happen and is there a cleaner approach? 为什么会发生这种情况,有没有更清洁的方法?

Error 错误

The type is defined in an assembly that is not referenced. 类型在未引用的程序集中定义。 You must add a reference to assembly 您必须添加对程序集的引用

Resolved 解决

A constructor with the same number of arguments must be evaluated through implicit conversion as to which function member(constructor) would be better. 具有相同数量参数的构造函数必须通过隐式转换进行评估,以确定哪个函数member(constructor)更好。

Hence why I needed to add the reference to the second project so the compiler could determine which constructor was better. 因此,为什么我需要将引用添加到第二个项目,以便编译器可以确定哪个构造函数更好。

If the constructors don't have the same number of arguments, evaluation doesn't need to occur, and the compiler doesn't need the reference to the second project. 如果构造函数没有相同数量的参数,则不需要进行求值,并且编译器不需要引用第二个项目。

Solution

Made just one method to handle all instances 仅制作一种方法来处理所有实例

public static void LoadProgressIndicator(object parent_control)
{
 if (parent_control is XtraForm)
    LoadProgressIndicator(parent_control as XtraForm, null, null, null);
 else
 {
    if (parent_control is XtraUserControl)
       LoadProgressIndicator(null, parent_control as XtraUserControl, null, null);
    else
    {
       if (parent_control is System.Windows.Forms.Form)
          LoadProgressIndicator(null, null, parent_control as System.Windows.Forms.Form, null);
       else
          LoadProgressIndicator(null, null, null, parent_control as System.Windows.Forms.UserControl);
    }
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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