开发者

Is it possible to distinguish types with identical fully qualified names?

The scenario is I would like to be able reference two similar 3rd party assemblies (e.g. assem1 and assem2) which both define a type with the sa开发者_运维百科me fully qualified name (e.g. Example.MyType). Is there any way to distinguish between these and refernce them seperately? I believe the answer is no but confirmation or correction would be handy.

Edit: Answered for C# 2.0 and higher below but need an answer in VB.Net 1.1


You can certainly do it in C# - you need to use extern aliases to specify which one you want in each case. Anson Horton has a walkthrough which is useful.

I don't know whether VB has a similar feature.

Of course, it's worth avoiding this situation if you possibly can :)


Maybe I misunderstood the question; if you want to reference it as part of a project (e.g. in VS), this isn't going to help you. But if you need to reference the type in a config file or whatever, the following does work:

Use the fully qualified name including the assemly name (best if the assembly is strong named), and you can tell them apart. Have a look at Type.AssemblyQualifiedName for more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜