简体   繁体   English

VB.net VS2010:动态对象类型更改为与类名称匹配

[英]VB.net VS2010: Dynamic object type that changes to match class name

I tried to search a bit before asking but I really had no idea what to search for on this one so here's what I'm looking for: 在询问之前,我尝试过搜索一下,但是我真的不知道该搜索什么,所以这就是我要寻找的内容:

I need a way to declare an object in VB.net so that I can set it to the current class(using the class as the object type) but if the class name changes then the object type changes to match the new class name. 我需要一种在VB.net中声明对象的方法,以便可以将其设置为当前类(使用类作为对象类型),但是如果类名称更改,则对象类型将更改为与新的类名称匹配。 Here's an example. 这是一个例子。

Class UhhWhat 班级

Dim L As List(Of UhhWhat) Dim L As List(OfUhhWhat)

Sub add() 子add()

  L.Add(Me) 

End Sub 结束子

End Class 末级

So if this were my code and someone copied it to a new class with a different name say... "UhhNo" then I would want the "List(Of UhhWhat)" to change to "List(Of UhhNo)". 因此,如果这是我的代码,并且有人将其复制到一个具有不同名称的新类中,说...“ UhhNo”,那么我希望将“ List(Of UhhWhat)”更改为“ List(Of UhhNo)”。

Does that make sense? 那有意义吗? I'm not really stuck on having the name for the object type, I just want something that will function like the List object's Of T but use the current class' type rather than a type supplied to a subroutine. 我并不是真的想知道对象类型的名称,我只想要可以像List对象的Of T一样起作用的东西,但是使用当前类的类型,而不是提供给子例程的类型。 I would like this done when the code is written, not at runtime because I need intellisense to continue to function for the new type. 我希望在编写代码时而不是在运行时完成此操作,因为我需要智能感知才能继续为新类型起作用。

Lastly, I do know that simply using "List(Of Object)" would help my problem.. however this will not work for intellisense and I have heard that declaring an object as "object" type is slower than if you declared it as a specific type. 最后,我确实知道简单地使用“ List(Of Object)”可以解决我的问题。但是,这对于intellisense不起作用,而且我听说将对象声明为“ object”类型要比将其声明为a慢。具体类型。

To sum it up what I'm looking for is a way to change the object type to whatever the programmer changes the class name to, automatically. 综上所述,我正在寻找一种方法,可以将对象类型自动更改为程序员将类名更改为的类型。

Thx a bunch :) 谢谢一堆:)

--EDIT-- I found the solution I was looking for in a rather simple place.. the VS rename function.. ahh another time when the answer was so simple. -编辑-我在一个相当简单的地方找到了我正在寻找的解决方案.. VS重命名功能..嗯,又一次答案很简单。

Kudos to David W for their patience with me, thx a bunch David W! 感谢David W对我的耐心,谢谢David W! I hope i didn't bug ya too much with my vague ideas :) I appreciate the suggestions :) 我希望我不要因为含糊的想法而烦恼很多:)我很欣赏这些建议:)

在解决方案资源管理器中,重命名类文件时,Visual Studio将相应地修复相应的类名。

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

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