Autocompleting initializer with Resharper 6 in Visual Studio 2010

女生的网名这么多〃 提交于 2019-12-04 16:20:09

问题


I was wondering if there is any way to shortcut the process of object initialization with VS 2010 and Resharper (6). When presented with the yellow tool tip below I'd like to have it create an assignment for each field.

For instance, it would generate:

Contact = ; ContactId = ; CreateDate = ; etc, etc

(one for each property).


回答1:


ReSharper code completion works exactly this way. As soon as you've typed in the braces, press Ctrl+Space to get the list of all properties:

var data = new Data {|}

Then, after entering a comma to delimit properties, ReSharper completion will only show properties that you haven't yet initialized. More importantly, when you complete a property name, it inserts the property and the equals sign.




回答2:


Still not answered satisfactorily in another (duplicate) question: Is there a way, at design time, to initialize an object with all properties in Visual Studio 2010?

Closest answer would be to create a custom Code Snippet or Resharper Live Template, but I only see a macro that triggers "smart completion", which is the CTRL+SPACE suggestion seen elsewhere. I'm offering this incomplete answer in case it's easier to remember an alias rather than a shortcut key.

I'd still like it to perform smart completion on that popup list, which is really what the question is asking for. You might also be able to create a custom macro that will accomplish this.

(I'll keep looking and update this answer if I find anything.)



来源:https://stackoverflow.com/questions/6668652/autocompleting-initializer-with-resharper-6-in-visual-studio-2010

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