简体   繁体   English

将方法移动到新文件并保留在同一类中(使其成为部分类)

[英]Move method to new file and keep it in the same class(make it partial)

I have a lot of classes with several methods. 我有很多使用几种方法的类。 And i need to separate each method of the class in its own file, but kept they in the same class( make it partial). 而且我需要将类的每个方法都隔离在自己的文件中,但要将它们保留在同一类中(使它成为局部的)。

Exploring the R# 6.1 options i haven't found linear possibility. 探索R#6.1选项时,我没有发现线性可能性。 May be there are hidden options? 可能有隐藏的选项?

Thanks 谢谢

Added: 添加:

This refactoring is not usual because this code is UI tests, that grouped in class by the part of functionality. 这种重构并不常见,因为此代码是UI测试,按功能部分在类中分组。 We need to separate them to be able to work on them separately from source control. 我们需要将它们分开,以便能够与源代码控制分开处理它们。

I'm using ReSharper 5.1 and do not know such refatoring in one step. 我正在使用ReSharper 5.1,一步就不知道这种引用。

The fastest way I know is: 我知道最快的方法是:

  1. Create partial classes 创建局部类
    Write a second declaration of partial class with empty body and copy/paste or double (Ctl+D) it so often as the count of different files should be. 编写第二个带有空主体的部分类声明,然后复制/粘贴或加倍(Ctl + D),这取决于不同文件的计数。
  2. Create files 建立档案
    Go to every class declaration, press Ctrl+Shift+R and select Move To Another File... , enter a new file name and press OK . 转到每个类声明,按Ctrl + Shift + R并选择Move To Another File ... ,输入新文件名,然后按OK
  3. Move methods 移动方法
    Do for every method to move: Go to method, press Alt+Enter , select Move declaration(s) to another type part and select file. 为要移动的每种方法执行以下操作:转到方法,按Alt + Enter ,选择“ 将声明移动到另一种类型的零件”并选择文件。

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

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