There is a visual studio shortcut to implement abstract methods as discussed here:
visual studio 2012 shortcut to implement interface
When I use the shortcut, these methods are added to the bottom of the file. How can I set this up to add them to the top of the file instead?
When I use the shortcut, these methods are added to the bottom of the
file
It seems a bit more complex than that.
If you have a class with only public methods, it will add the new methods at the bottom.
If you have a class with only private methods it will add the new methods at the top.
Most likely what's happening is the Roslyn compiler is trying to place these public methods before any existing private ones, since its the compiler doing the work, I'm 99% sure there's no way to change this. To be 100% sure you'd want to look at the compiler source code:
https://github.com/dotnet/roslyn
I don't have Resharper installed.. I want to see all subclasses inherited from IActionResult and there is no things like show derived classes in object browser and class view.
I try to install a extension TypeHierarchyViewer(https://marketplace.visualstudio.com/items?itemName=munyabe.TypeHierarchyViewer) but it is not working (even using the example List, just remains blank) .
So what should I do?
I use this function frequently developing java application using eclipse..It seems there is no out-of-box tool in VS2017 or I just missed some things??
(Go To Implementation says the symbol has no implementations)
(Same in class view)
I have searched many "solutions"(like Visual Studio: How do I show all classes inherited from a base class?) but not work or need other tools(or just see the doc?).
I want to see if there anyway to do it just using VS.
Before I thought VS was a very good IDE but I can't image it lacks so much basic functions...(so there is Resharper...)
And I find there is derived types but in Solution explorer:
But you can't input the class you want And if I input IActionResult in search box it will not find it(not in the my source and I don't implement it).
After trying..I find VS support it in solution explorer...
But it's hard to use...
I need to find some classes or interface in my source code related to the class or interface I want and use derived type and implements to find the it..
It looks like:
(I find a class and navigate to object, it lists all classes .Then I find ActionResult and choose implements find IActionResult, finally I can see all derived classes above... ...)
emmmmm
it seems there is no direct way using VS(although I can get all sub classes using solution explorer but it's too verbose...) to get the result I want.
Finally I choose to use dotpeek(I don't want to buy resharper because I just study ASP.net core not for work)
I open C:\Program Files\dotnet\sdk\NuGetFallbackFolder in dotpeek where the dependencies located.
Then using Hierarchies get the result.
feel a little disappointed about VS. Not so strong before I heared.
Thx for help. :)
This is more of a design issue with Visual Studio [>=2010].
Example: When you implement IDisposed in a VB environment, in the body of Public Sub Dispose there are numerous comments and a branch about how to do it. Also the field disposed is automaticaly inserted to the Class.
Now when I design an Interface or abstract Class, is there a way to define some kind of 'template' for each abstract procedure/property body, containing comments or even branches/loops?
Edit:
Now i realize that the C# environment has a different approach to these templates/snippets, but i'd like to make them available for developers in both environments.
These code snippets should be inserted preferebly when using Implement Interface or Implement abstract Class or when TABing after selecting an overridable procedure.
Edit2:
Ok, the Snipped Editor did indeed provide a reasonable solution.
Essentially i have to update my custom snippets for each target instance of VS at the path
C:\%ProgramFiles%\Microsoft Visual Studio %VSVER%\%ENV%\Snippets\%LANG%\...
I hoped there was a way to provide VS with the snippets via the referenced Assembly/Resource only.*
I have a class which has 10 methods.
What i want is to create an interface of that class, i.e the interface will contain only the signature of those 10 methods.
Can it be done easily in .NET using Visual studio?
I am asking this question because I am changing the architecture of my project and for every class present in my project i need an interface.
If you are using VS 2010 you can do this by just going to the Refractor Menu and click Extract Interface, you can also use the key board short cut Ctrl+R, I
Ctrl+C, Ctrl+V. Pretty easy. think about it!
if seriously, Ctrl+R, Ctrl+I - will extract an interface of the class.
It certainly can. You can use the Extract Interface refactoring to do it for you.
Sounds like a job for ReSharper's Extract Interface refactoring feature.
There are several way to go:
Way 1: Using Visual Studio: Right Click on your Class body and the choose Refactor>Extract Interface, then choose Members and provide Interface name or keep default name if you want leading I in your class name.
Way 2: After opening your class, press Ctrl+R,I(case insensitive) and then do rest job according to Way 1
Suppose you have an interface defined in C#. What is the easiest method to find all classes that provide an implementation of the interface?
The brute force method would be to use "Find References" in Visual Studio and manually look through the results to separate out the usages from the implementations, but for an interface in a large codebase that is heavily referenced with relatively few implementations, this can be time consuming and error prone.
In Java, running javadoc on the codebase (using the -private option to include private classes) would generate a documentation page for the interface (e.g. Comparable) that includes all implementing classes for the interface as well as any subinterfaces (though it doesn't include implementing classes of the subinterfaces, these are relatively easy to determine by drilling down into the listed subinterfaces). It's this functionality that I'm looking for but with C# and Visual Studio.
In plain Visual Studio (since 2010) you can right click a method name (definition in interface or implementation in other class) and choose View Call Hierarchy. In Call Hierarchy window there is "Implements" folder where you can find all locations of the interface method implementation.
(Edit based on comment...)
If you have ReSharper installed:
In Visual Studio, right click on the type name and choose "Go to Inheritor". Alternatively, select the type name, then go to ReSharper/View/Type Hierarchy to open up a new tab. (The menu will show you the keyboard shortcut - this can vary, which is why I explained how to find it :)
If you don't have ReSharper:
You can use Reflector, which is able to show you all the type hierarchy very easily - just under the type name are expandable items for base types and derived types. Similar tools are available such as ILSpy and dotPeek.
Buy ReSharper - it's a great tool :)
Put the cursor to class or interface type and
CTRL + F12
With Visual Studio 2010+
Right click a member method and choose view call hierarchy. Expand the Implements folder. This lists all the types that implement the interface the method belongs to.
With Resharper 7
Right Click the interface > Navigate To > Derived Symbols. The symbols listed in bold derive directly from the interface. Non-bold symbols derive from a superclass.
For those using Visual Studio 2015, there is this awesome extension called Go To Implementation. Give it a try.
Once you've installed the extension, you can just right click at any occurrences of the interface (e.g. IUrlShortener) and click on Go To Implementation menu. If you only have one class that implements the interface, clicking the menu will bring you directly to the class. If you have more than one class that implements the interface, it will list all the classes.
For those using Visual Studio 2015, install Visual Studio 2015 Update 1 RC. From the Visual Studio blog:
Today we released Visual Studio 2015 Update 1 RC, which builds on the Update 1 CTP we released three weeks ago. In addition to the features introduced in the CTP as described here, the Release Candidate includes the following:
Go To Implementation. The feature many of you have been waiting for: just right-click on an interface or abstract method and select this command to navigate to the implementation.
I don't think this functionality is inbuilt into VS but IIRC Resharper has this.
You could do a regular expression search for the interface.
:(\ *[^},]+,)*\ *IMyInterfaceName
CTRL+SHIFT+F launches the following window:
I prefer the "Navigate To..." option. With your cursor on the function call, try the following:
Shortcut Key:
Ctrl+, (Ctrl+comma)
Menu:
Edit Menu
Click "Navigate To..."
Benefits:
Doesn't show all references like "Find All References"
Shows the
"type" of the implementation so it will note which is your interface
Use Shift + F12 to show all references, including the definitions.
If you use resharper ALT + END shortcut might help to find all Inheritors.
I've heard tell (no experience myself) that doxygen is to .Net as as javadoc is to java.