C# Interactive as VisualStudio/ReSharper plug-in - c#

I'd like to do some "structural meta-programming" in C# (like in other languages as Smalltalk).
For doing so I'd like to script, using a REPL-like tool that should run "inside" VisualStudio. Doing so it would be possible to try ideas, execute refactorings programmatically, etc. from the VisualStudio itself and making use of the full meta-model capabilities it and ReSharper has.
I found that the tool "C# Interactive" allows to script in C# as a common REPL, but runs as a "separated process", not inside VisualStudio.
Is there an tool like "C# Interactive" that runs as VisualStudio/ReSharper plug-in? Any hint, idea, etc. will be welcome :-)

You can load Roslyn into your interactive session, then use its APIs to manipulate your code.
Create an MSBuildWorkspace, load your solution, then explore the Roslyn APIs to your heart's content.
No Visual Studio needed.

You may find my Visual Commander extension useful. The command code provides full access to the VS automation model and executes inside Visual Studio.

Related

CustomVisualizer extension in VS 2019

We are using a C++ visualizer which visualized the class content to DataTip using IDkmCustomVisualizer. Something what natvis already has but more advanced. The extension is written in C# and worked beautifully in VS 2017. Since we switched to VS 2019 it stopped working due to new mechanism introduced in VS 2019 (external process).
https://learn.microsoft.com/en-us/visualstudio/debugger/visual-cpp-custom-visualizer-compatibility?view=vs-2019
Of course if I disable the "Load debug symbols in external process (native only)" option in VS my extension starts to work. However our project is huge and we like the new external process mechanism.
I also tried to add WorkerProcessSupported="true" to my vsdconfigxml. Based on:
https://github.com/Microsoft/ConcordExtensibilitySamples/wiki/Worker-Process-Remoting
However my visualizer is not called. I was not even able to get work the provided C++ extension example:
https://github.com/Microsoft/ConcordExtensibilitySamples/wiki/Cpp-Custom-Visualizer-Sample
The Worker-Process-Remoting code mentioned to split my class. Unfortunately without any example/tutorial I'm not able to do it.
Any advice how to solve this?
Many thanks for any help :-)

Intellisense for available 'using/import's in C# with Visual Studio Code

Edit: Vidual Studio Code and Visual Studio are 2 different things. Yes it's confusing but I know that VS has this feature, I'm asking about VS code.
Is there some extension/setting that makes Visual Studio Code's c# have Intellisense for all available namespaces, including those that were not yet imported, and then imports them when selected?
Example: Collections are not yet imported and I want to type IEnumerable and import it. Being the average programmer this is quite tedious and I might screw up the spelling or capitalization, and then have to press ctrl+.. I would like to just be able to type "ienu" and then IEnumerable would pop up and would be autocompleted and auto imported.
This feature exists for Typescript in VScode (thanks to an extension), and even for C# but in Visual Studio with the Resharper extension.
I have searched everywhere for this feature but it seems to me like it doesn't exist. It honestly feels insane to code without this.
If you use "C# extension" for VSCode (this https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp)
you can try follow next steps:
Right click on C# extension
"Extension settings"
In opened "Settings" tab, add import in search area
Enable Checkbox
(Screenshot of this step)
Enjoy autoimport without "special" extension (Screenshot)
I just went ahead and made the extension:
https://marketplace.visualstudio.com/items?itemName=Fudge.auto-using#overview
Currently it supports only the base C# libraries but I can make it use additional nugget libraries as well if there is demand for that.
As of 24/11/2020 the official C# extension supports this feature, see other answer.
There are some sort of solution for your problem that might help if you write the complete key word and don't want to write the using system or any library you can just put cursor on your key word and press alt+enter it will automatically add the library .but if you are not using library and want to auto complete key word of that library it's possible with re-sharper. you can also use Ctrl+space if your visual studio is not giving you auto recommendation

Custom widget design time support?

The GUI designer for MonoDevelop (Stetic) provides design-time support for widgets, such as the Notebook widget, which has options for Insert Page Before and Insert Page After. It also allows me to drop child widgets onto those separate pages.
Is this implemented directly in Gtk#? Where can I examine the code for this? How can I implement this for my own custom widgets? I want to create a notebook-like navigation control (similar to MS Outlook 2007/2010/2013) that can be designed using drag-and-drop with Stetic.
I have already tried searching through the source for MonoDevelop and Gtk#. It seems to me this may be implemented in a similar manner with additional classes and attributes like in Visual Studio with Attributes and Design-Time Support but I cannot find any evidence of that.
In MonoDevelop, Stetic is defined as a member in AddIns. Technically, it is always available/installed, so it is not something you deal with from the Add In Manager.
So you are looking for:
MonoDevelop.GtkCore.dll
libstetic.dll
libsteticui.dll
During a monodevelop build, assuming you have monodevelop code local, those get built and placed in:
monodevelop/main/build/AddIns/MonoDevelop.GtkCore
The source code that you are looking for is at:
monodevelop/main/src/addins/*
I would highly recommend in order to jump-start you:
git clone the monodevelop source repo
cd into the repo
./configure --help (to figure out what options you need to use)
Once you can build monodevelop, you can use that build version or (Xamarin
Starter+) to open workspace MonoDevelop.mdw (in root dir of repo)
Navigate to:
Main / Addins / MonoDevelop.GtkCore / libstetic
Main / Addins / MonoDevelop.GtkCore / libsteticui
Have fun storming the castle ;-)
The Stetic designer in MonoDevelop simply does not support the concept of "pluggable" widget design or commands. It's just written the way it is for the controls it supports and anything else has to be added via the Custom Widget widget and manipulated via code.

Visual Studio or Resharper extension to decompile code

Does anyone know of a Visual Studio extension that will decompile assemblies and allows you to view code in Visual Studio for a given class instead of having to leave VS and use ILSpy or other "external" reflection tools? I Know Resharper also has a reflection tool but it would be nice if you could kick it off within VS.
Newer versions of Visual Studio 2017 now include an experimental feature called navigation to decompiled sources. It requires you to explicitly enable it (and restart Visual Studio), but once you do, you can see decompiled source code for assemblies your code references.
For instance, if you put your caret (text cursor) over the name of a method in a method call and press F12 (by default) it will open a new tab right in the IDE that shows the decompiled source code for that method. Microsoft says this uses ILSpy behind the scenes, but this is a lot more convenient and doesn't require you installing anything new.
I Know Resharper also has a reflection tool but it would be nice if you could kick it off within VS.
You can. With the cursor on an identifier, choose ReSharper | Navigate | Navigate To... (the keyboard shortcut in the VS scheme is Alt+`), and choose Decompiled Sources.
This uses the same decompilation engine as dotPeek, the standalone tool.
Note that within such a decompiled source, you must continue to use this same navigation method to follow definitions, as F12 or Ctrl+click will go back to the Object Browser.
Assuming the default short-cut keys where pressing F12 while a class/method is in-focus, you can set ReSharper to automatically decompile the reference. This ends up working great and it's as if the external assembly reference was like any other class in your source solution.
Example of source you are directed to when pressing F12 while focused on new HttpClient()
I suggest you to use .NET Reflector which has a built-in VS integration for assemblies decompilation and is far, far better than Resharper. Have a look at this page for further knowledge.
http://ilspy.net/ is free and Open Source. And has a plugin for Visual Studio.

Are there any emacs or vim editors with code completion plugins for C#?

It would be nice if it did both a list of methods to choose from and the list of potential input parameters. This was done for powershell and I was curious if there was any similar functionality implemented for emacs or vim?
Clarification:
A fellow developer I work with wants to use either vim or emacs for the low overhead without running visual studio. In essence he would like to be able to write tests, edit code in emacs or vim then just run NANT scripts to compile the code and run the tests. The only feature from Visual Studio he wants is code completion. The rest he can live without for 98-99 percent of the time.
You can use a vim editor emulator for Visual Studio.
http://www.viemu.com/
I haven't come across an emacs mode that would offer code completion suggestions based on "knowledge" of the API(s) that the user's environment is offering. To a lot of people this is an issue which prevents them from attempting to use Emacs or VIM when working with rich/large/unwieldy (delete as applicable) APIs.
However I am wondering how much of a problem this would present during day-to-day work. I've been using Emacs with C#-mode to crank out quite a lot of C# code. I also tend to run dabbrev-mode or pabbrev-mode, which tends to take care of the more common function and variable names I tend to use. To my eternal shame I have to admit that I tend to have a browser open on the MSDN website to look up the rest - those APIs that I don't use often enough to remember. Another potential helper that your colleague might want to look into is icicles, which may also be a step in the right direction. Neither of these libraries however will offer the full breadth of completion support that something the like Visual Studio IDE will offer. I'd see this as part of the trade-off when using a more efficient editor.
As an aside, if your colleague is working in a team and other members working on the same project are using Visual Studio, MSBuild might offer a better solution for building outside of VS than Nant as MSBuild reads the same solution and project files that VS uses (in fact a lot of the build work in VS2008 is handled by MSBuild). The syntax isn't too far away from Nant and with the community tasks added (which gives you NUnit integration etc) and it'll ensure that everybody is using very similar mechanisms to build the executables.
The furthest along completion I've seen for C# is at this blog, specifically at this post. (Blog link included for context and other Emacs posts.)
If you can live with dumb completion, you might be able to roll your own with tags and tag completion.
A previous stack on the same issue.
Your source code should be processed through the CEDET framework: http://cedet.sourceforge.net/
Then either use the example UIs bundled with cedet or else try any of these two:
- company-mode: http://nschum.de/src/emacs/company-mode
- completion-ui: http://www.dr-qubit.org/emacs.php
both supporting CEDET as a completion search backend.
apa!
for emacs and C# you can look at this tool : http://code.google.com/p/idebridge/
OmniSharp provides contextual intellisense for C# in vim.
Some of the suggestions in Eclipse Style Function Completions in Emacs for C, C++ and JAVA? may be relevant for emacs.
Not c# specific, but still.
I have found the http://code.google.com/p/csense this is an emacs c# intellisense/code sense. I found it from this blog post http://osdir.com/ml/emacs.sources/2007-11/msg00018.html, this may be close to the answer I was looking for.
After looking further it has not been updated since November 2007, looks stale to me.
For Vim, you can install insenvim. It support for the C# code completion.
After download the plugin you could install the installation file or install manually by following steps:
Copy the file cs_vis.vim into your $VIM\vimfiles\ftplugin directory.
Copy the file csft.dll into your $VIM_INTELLISENSE directory.
Copy CSVimHelper.dll,reg.bat to your $VIM_INTELLISENSE directory.
Run reg.bat to register the dlls. You need to set the directory gacutil.exe
in the path. You need the latest version of .NET SDK.

Categories