简体   繁体   English

Visual Studio Designer中的别名和名称空间冲突

[英]Alias and namespace conflict in Visual Studio Designer

I have a namespace conflict between two referenced assemblies: 我在两个引用的程序集之间存在名称空间冲突:

ie, I'm referencing Foo.A.Foo and Foo.Bar, so when I say I want Foo.Bar.Control, VS is trying to find Foo.A.Foo.Bar.Control 即,我引用的是Foo.A.Foo和Foo.Bar,所以当我说我想要Foo.Bar.Control时,VS试图找到Foo.A.Foo.Bar.Control

I can twiddle the Designer.cs code by adding new global:Foo.Bar.Control(), but as soon as I change anything, VS switches back. 我可以通过添加新的global:Foo.Bar.Control()来缠绕Designer.cs代码,但是一旦更改任何内容,VS就会切换回去。

I know there's something about adding aliases directly to the reference, I've tried but haven't managed to find the right combination (inline alias, using alias, reference alias). 我知道有一些直接将别名添加到引用的方法,我已经尝试过,但是没有设法找到正确的组合(内联别名,使用别名,引用别名)。

Help? 救命?

"extern alias" may be what you mean, but I'm not sure what the designer will do with it, unfortunately... “外部别名”可能就是您的意思,但是不幸的是,我不确定设计师将如何处理...

I'm not even sure that's what you're after though - that's normally for two types from different assemblies with the same name. 我什至不知道那是您要追求的-通常用于来自具有相同名称的不同程序集的两种类型。

You can write namespace aliases with a using directive , eg 您可以使用using指令编写名称空间别名,例如

using FooControl = Foo.Bar.Control; 使用FooControl = Foo.Bar.Control;

but again, the designer is going to rewrite your code... 但是设计师再次要重写您的代码...

OK, this isn't the answer, but it's what I found for a workaround: 好的,这不是答案,但这是我找到的解决方法:

namespace FooBar
{
    class FooBarControlHack : Foo.Bar.Control { }
}

So I can do the following in the Designer.cs : 因此,我可以在Designer.cs中执行以下操作:

this.fooBarControl = new FooBar.FoorBarControlHack();

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

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