如何将一个类移动到另一个包中?

时间:2021-12-08 21:22:24

In Visual Studio I have a lot of classes and UserControls that I have to move into another namespace. In eclipse I can do it with updating all the references automatically. In Visual Studio I couldn't find a similar function. How is this possbile in Visual Studio?

在Visual Studio中,我有很多类和UserControl,我必须移动到另一个命名空间。在eclipse中,我可以自动更新所有引用。在Visual Studio中,我找不到类似的功能。这在Visual Studio中是如何可能的?

4 个解决方案

#1


2  

There's no such functionality provided in Visual Studio. Resharper has such feature.

Visual Studio中没有提供此类功能。 Resharper有这样的功能。

#2


3  

If you mean moving between assemblies:

如果你的意思是在组件之间移动

For existing built code you should add:

对于现有的构建代码,您应该添加:

[assembly:TypeForwardedTo(typeof(SomeNamespace.TheControl))]

to the original assembly (that no longer contains TheControl). Then the CLR will sort everything out for you for existing built code without having to update the references.

到原始程序集(不再包含TheControl)。然后,CLR将为您现有的构建代码排序所有内容,而无需更新引用。

However, for building code you will still need to update the references; I don't think vanilla VS has that built in.

但是,对于构建代码,您仍需要更新引用;我不认为香草VS有内置。

#3


1  

Rename is supported in VS for reference update, but not file or class movements

VS中支持重命名以进行参考更新,但不支持文件或类移动

#4


1  

I reccomend Resharper. It's really powerful refactoring tool fos VS. VS becomes even possible to use after installing it;) And it has tool for moving classes, methods, pulling up, pushing down, renaming and many more.

我推荐Resharper。它是真正强大的重构工具fos VS. VS甚至可以在安装后使用;)它还具有移动类,方法,上拉,下推,重命名等工具。

#1


2  

There's no such functionality provided in Visual Studio. Resharper has such feature.

Visual Studio中没有提供此类功能。 Resharper有这样的功能。

#2


3  

If you mean moving between assemblies:

如果你的意思是在组件之间移动

For existing built code you should add:

对于现有的构建代码,您应该添加:

[assembly:TypeForwardedTo(typeof(SomeNamespace.TheControl))]

to the original assembly (that no longer contains TheControl). Then the CLR will sort everything out for you for existing built code without having to update the references.

到原始程序集(不再包含TheControl)。然后,CLR将为您现有的构建代码排序所有内容,而无需更新引用。

However, for building code you will still need to update the references; I don't think vanilla VS has that built in.

但是,对于构建代码,您仍需要更新引用;我不认为香草VS有内置。

#3


1  

Rename is supported in VS for reference update, but not file or class movements

VS中支持重命名以进行参考更新,但不支持文件或类移动

#4


1  

I reccomend Resharper. It's really powerful refactoring tool fos VS. VS becomes even possible to use after installing it;) And it has tool for moving classes, methods, pulling up, pushing down, renaming and many more.

我推荐Resharper。它是真正强大的重构工具fos VS. VS甚至可以在安装后使用;)它还具有移动类,方法,上拉,下推,重命名等工具。