具有相同类别名称的DLL [英] Dll with same class name

查看:114
本文介绍了具有相同类别名称的DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个外部dll,其类名称为: User 。我将其导入到另一个程序中,该程序具有相同的类名 User 。现在,如果我输入: User。以访问dll方法,则intellisense会向我显示类 User 当然是我自己的程序。一个示例:

I have created an external dll that have as class name: User. I imported it in another program, this have the same class name User. Now if I type: User. for access to the method of dll, the intellisense instead show me the method of the class User of my own program of course. A practice example:

[DLL]:

public class User{
  ... some method ...
}

[实现dll的程序]

using User;

public class User{

      public void getUsers(){
            User. //can't access to dll method
      }
}

任何想法解决这个问题?请注意,名称空间是不同的。

Any idea to fix this? Please note that the namespace are different.

推荐答案

很难从您的示例中看出来,但看起来您想要的是外部别名指令。您可以在此处阅读有关它们的简短教程:

It is hard to tell from your example, but it looks like what you want is an extern alias directive. You can read a short tutorial on them here:

https://blogs.msdn.microsoft.com/ansonh/2006/09/27/extern-alias-walkthrough/

命令行格式的文档在这里:

And the documentation for the command line form is here:

https://msdn.microsoft.com/zh-CN/library/ms173212.aspx

让我们假设您的DLL程序集是Foo.DLL。因此,您要做的是,首先为引用的Foo.DLL 添加别名,将别名称为 Foo。第二,在您的命名空间指令中添加指令:

Let's suppose your DLL assembly is Foo.DLL. So what you would do is, first add an alias to the referenced Foo.DLL, call the alias "Foo". Second, add a directive to your namespace directives:

extern alias Foo;

然后在您的程序中,您可以说 Foo :: User ,编译器将知道您是指 Foo.DLL 中的 User ,而不是当前版本中的

Then in your program you can say Foo::User and the compiler will know that you mean the User from Foo.DLL and not the one from the current compilation.

这篇关于具有相同类别名称的DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆