Anonymous Type to Real Class Refactoring

给你一囗甜甜゛ 提交于 2019-12-18 15:40:34

问题


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.


回答1:


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:



来源:https://stackoverflow.com/questions/5291427/anonymous-type-to-real-class-refactoring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!