Find method calls in Visual Studio 2015 - c#

is there a function or VS-Extension to find all method calls in c# code?
For example, i have a bitmap object which calls in some function myBitmap.Save(stream, ImageFormat.Gif). My goal is to find all .Save calls from Bitmap-Type in my code. I hope everybody understand my question.
I know, that i could use Find and Replace and search for ".Save(". But this also returns XmlDocument.Save() and other ".Save(" calls. This is not what i want. I want only .Save calls to the Bitmap-Type.

Visual Studio has options to search for various objects. What you have described (find all members of certain type) is called Find all references.
Simply right click on the method name (in the text editor, object browser, class viewer, etc.) and you should see context menu with such option:
Using this option will brings up Find Symbols Results window with matches:
P.S.: screenshots are taken from the google image search for an overview and may not necessarily match VS version or the case.

Related

Searching and navigating through code in visual studio

I work on reality big project. And sometimes i get the need to search for some specific keyword inside A single c# file that has many calls of other functions from other c# file.
So i want to know if there is any easy way that could search for give phrase or keyword inside the current file and inside all the functions that my current file calls to. But not in the entire solution or inside the whole project.
For inside the file that's Ctrl+F.
Otherwise Code Search in VS2022 is very fast. Normally it's bound to Ctrl+T.
Introducing a New Way to Search Your Code and Visual Studio Features
Code search in Visual Studio 2022 is about to get much faster).
There also are the Go To options in the context menu that could help:
Finally, at the top of the editor window you can switch between classes and properties/methods.
BTW. You can address the large solution problem by splitting the codbase into multiple smaller solutions that only include parts of the overall code. This has some drawbacks, but overall it works very well in my experience.

How do I automatically generate documentation/comments in Monodevelop?

Monodevelop automatically generates verbose documentation for functions and classes if "///" is typed in the appropriate place, upon typing the third '/'.
I want it to go over all of my code, though - I thought there was some button somewhere, and I looked around in the drop-down menus, tried right-clicking file names, etc.
I could not find such an option - does it not exist? I could not find a plugin that does that either.
Try to use Edit-> Document buffer.
It will make /// comments for all your public methods/classes without any comment upon it in current file.
It won't work if you have // comment upon method/class or for protected/private elements.
It is not possible. Your options are:
Manually typing three slashes before each and every function
Using an external tool
Online searches have not come up with any plugins for monodevelop that would do that, and the option does not exist in the vanilla IDE.

VS2010 Extensibility: Custom document formatting

Good afternoon,
I've created a visual studio package that registers the Verilog language as a valid content type.
I've got syntax highlighting, outlining, smart indenting, etc all working.
However, I would like to be able to get Visual Studio to automatically format the entire document via Edit->Advanced->Format Document/Selection. Currently these options are invisible, and I expect that I have to let VS2010 know (somehow) that these methods can be called, and provide the correct methods to do this formatting.
I can't seem to find any reference to formatting in the VS2010 SDK and documentation. I was hoping that ISmartIndent would be the solution I was looking for, but it seems that this code only runs on an empty line, or when the enter key is pressed.
Does anyone have any tips or ideas on how I can solve this problem?
Thanks,
Giawa
Edit: I'm using the managed extension framework introduced with VS2010 to accomplish this. I'm writing in C# (and just added the c# tag to my question). Thanks
MEF is not the right way to accomplish the task of creating a language service. Instead, the Managed Package Framework (MPF) should be used to register the language service and perform tasks such as syntax highlighting, outlining, parsing, formatting, parsing, etc.
Since my question was about formatting, I'll cover a little bit of it in my answer. You must override the ReformatSpan method in the custom Source object that you've creating for your language service. There's a good example on the MSDN webpages for VS2005 (applicable to VS2010 as well).
You can also force formatting at any time by calling the ReformatSpan method directly. Here's a working example from my code:
Region region = service.GetRegionContainingLine((line > 0 ? line - 1 : 0));
if (region != null)
{
using (EditArray mgr = new EditArray(this, service.LastActiveTextView, true, "Reformat Brace"))
this.ReformatSpan(mgr, region.ToSpan());
}
Thanks to #James McNellis for pointing me in the correct direction.
Here you go: http://msdn.microsoft.com/en-us/library/ee197665.aspx

ASP.net c#, how do I know what to use?

I keep coming accross code samples online for ASP.net c#, however they never seem to list which namespaces they include, for example:
using System.Data.SqlClient;
etc etc
Am I missing something obvious or should I be expected to know exactly what namespaces each code example requires?
When I'm in that situation, typically I search for the class on MSDN. The documentation will tell you which namespaces contain the class.
If they don't include them, you can follow this list in order:
Find that they are in one of the namespaces listed in the "blank code file" template , or
In Visual Studio You can click the missing type and press shift+F10 or Ctrl+. To get the option to automatically add the using statement (if the assembly is referenced)
With Resharper, Select the type and hit alt+enter for Resharper to find the namespace for you, and add it to the usings (possibly even reference the assembly as well)
Go to MSDN and search the name.
Go to Google and search the name (honestly, I normally do this before hitting MSDN anyway)
Compain to the article author
If code samples use the assemblies that a project references by default, then you can hover on the class name and click shift+F10 which will add the using statement automatically. If the class is not in any of the referenced assemblies then you are out of luck and need to know in what assembly does the class resides.
A quick google search can help, and in time you will memorize the namespaces... Of course its best if samples included the namespace and reference info, but mostly they do not.
If you are viewing code in Visual studio, just hover mouse over class or object you want and you will get tool tip about it if assemly of that class is present or you can google for particular class.For example if you want to know more about 'DataTable'class, just google it and you will come to know that its part of Syste.Data namespace.
I'm with the OP on this one. Having to just magically "know" what namespaces are required seems supremely silly.
I spent some time before C# as a Java Developer, and the NetBeans IDE will resolve these for you automatically. Ctrl-Shift-I, and it will insert all the packages (ie, namespaces) you need. If more than one package defines the class you are resolving, a window pops up and lets you choose which one you want.
For as fine a product as VS is, I am incredulous that this feature is not included.

VS2005: how to find text in the current function

In the VS2005 code-editor using C#, how do you search for text in the current function only? It allows searching over the Current Document but I cannot see how to limit the search to only the current function.
Select the function's code and then a new option will be available in the dropdown list. This option is called Current Block. This will allow you to search only within that specific function.
From the source on MSDN: Quick Find, Find and Replace Window
Most of the time, your functions should be short enough that this really isn't an issue, and I mean that.
Occasionally, you might have an almost-legitimate need for some kind of indexing function that has a lot of distinct tokens. Even in this case, you should refactor to use a database or reflection or something, as this is the kind of thing that'll get your code featured on DailyWtf.com.
But if it's really unavoidable to have a function this long, if it's legacy code, or for some other weird reason, there are some things you can do:
The Find All References feature in visual studio lists all results at once, in order. You can size the window to show just the results in your function.
You can use partial classes to isolate your function to a specific file
Highlight the function with your mouse, and the Find/Replace dialog can search within selected text only.

Categories