匿名类型皇家类重构 [英] Anonymous Type to Real Class Refactoring

查看:99
本文介绍了匿名类型皇家类重构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单的方法重构匿名类型为一类?我经常原型我与匿名类型的代码,那么就得回去重新实现各个阶级,因为他们需要超越其局部范围内使用。我使用的ReSharper的,不知道如果有一个简单的方法来做到这一点。

Is there an easy way to refactor an anonymous type into a class? I frequently prototype my code with anonymous types, then have to go back and re implement the various classes as they need to be used beyond their local scope. I am using resharper and wondering if there is an easy way to do this.

推荐答案

使用ReSharper的5.1的(我会想到这已自4版本,第一个用C#3.0的支持)的,用光标从之前的任何位置刚刚结束<后code>} 在此代码:

Using ReSharper 5.1 (I would expect this has been available since version 4, the first with C# 3.0 support), with the cursor anywhere from just before the new to just after the closing } in this code:

        var v = new {Name = "Brian"};



弹出重构这个... 菜单(通常与<大骨节病>控制 + <大骨节病>移 + <大骨节病>研究),以及其中的一个选项是替换匿名类型名为类... ,它会弹出这个对话框:

bring up the Refactor This... menu (typically with Ctrl+Shift+R), and one of the options is Replace Anonymous Type With Named Class..., which brings up this dialog:

这篇关于匿名类型皇家类重构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆