Automatic addition of `using` in CodeRush

青春壹個敷衍的年華 提交于 2020-01-13 19:34:47

问题


I just installed CodeRush Pro (evaluation trial) for Visual Studio and I can say I like it much so far. Comparing to Resharper there is only one type of feature I'm really missing. It is the way CodeRush deals with using. When I type some class name that is not declared in some package listed in using, CodeRush underlines it red as an error(what it is) but if I hover over it with cursor it does not offer me to add using, it merely says it is "Undeclared element".

I have to use VS default using addition (move caret to the identifier, hover cursor over that really small box that appears under first letter, click the button that appears and choose for example using System form a drop down menu).

Is there a way how to configure CodeRush to offer mi add using when I hover a cursor over highlighted "issue"(that says Undeclared element)?

The second part of this is that Resharper has somethink called Type name completion. It some improved intellisense. Lets say you have no using declaration in your file. Then you type something like ICompar and press CTRL+SPACE. Of cause there will be no suggestions. But with Resharper you can press CTRL+ALT+SPACE and you get suggestions of all classes starting with ICompar even if they are not in using. When you choose one of them the correct using is automatically added for you.

Is there a way to make CodeRush behave this way ?


回答1:


PART I

Visual Studio

The default VS mechanism you mention is tripped using Ctrl+Period or Shift+Alt+F10

CodeRush Templates

Let me quote Mark Miller (Chief architect of CodeRush) for this part:

"CodeRush templates (like VS code snippets on steroids) will add namespaces as needed, so if you use templates to create classes, methods, variables, properties, events, and type references then the namespace references will be added automatically and you'll rarely need to use the VS feature for adding namespaces. To get started with the templates we recommend docking the CodeRush training window (DevExpress | Tool Windows | CodeRush) to the side of the editor and check that training window for tips and templates you can use to generate the code you need. Just type the template as it shows up in the window and expand it using the space bar."

Try the v-series, the m-series, the n-series and the t-series.

So what I mean by this is:

  • Launch the CodeRush training window (DevExpress\Tool Windows\CodeRush)
  • Dock it to the left
  • Back to the editor
  • Type 'v' (no quotes)
    • Careful this is context sensitive
      • Try this whilst the caret is in a class.
      • Try this whilst the caret is in a method.
  • Now look at the Training window.
  • You should see a few suggestions of further characters to type.
  • Type one of the suggestions and then hit space.

That was your introduction to the v-series of templates.

Feel free to check out the m-series, the n-series and the t-series.

Also note that the training window also provides suggestions when you are on a blank line.

Community Plugins

There is nothing built into CodeRush which provides "Add using for this type" functionality.

However there are numerous Community Plugins which add all sorts of functionality to CodeRush. This extensibility is one of the best features of CodeRush.

One plugin in particular Refactor_Resolve has functionality that might come close to what you describe.

PART II

I don't believe there are any intellisense enhancements provided by CodeRush at this time.

Sorry




回答2:


Not an answer, but giving my best poor mans crap workaround in case there isnt a better one... is Ctrl-Home (top of file) then usl and <space> (expand to using System.Linq) then Ctrl-Minus(Back to where we were - of course you can use the CR markers too).

(I have a request in the CR bugbase for this to be sorted)




回答3:


DX have built another sample around this. I wish it'd get into the CR product but I guess one shouldn't whine about free plugins (too much anyway).



来源:https://stackoverflow.com/questions/2883037/automatic-addition-of-using-in-coderush

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