VS2005: how to find text in the current function - c#

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.

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.

Find method calls in Visual Studio 2015

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.

building text editor with code completion feature

Presently I'm trying to build up a text editor for the PHP language which should have the feature of code completion, i.e. if i start to type a word a dynamically created drop down list will display all available keywords starts with my typed letters. Can any body suggest me how it can be done. Idea will be enough for me. If possible please provide me a link to such simple application build in C#.
Considering that in general it's not an easy task, so there is no some "easy" application.
Even if in general idea is not a rocket science. You need to define a dictionary of words, corresponding to some key. When you type "." (in C#) you have to pick from the dictionary all words corresponding to the key equal to the word found on left side from the "."
To do it real working applicaiton is not so easy. By the way I can recommend to have a look on MonoDevlop look on their editor.
I worked with it years ago to make a simple editor for DSL company needed, and spend not small amount of time to correctly understand intenals, integrate well "my new language", "detach" control from Mono and inject into our applicaitons, like a dockable window.
If I where you I would really try to avoid the wheel... code completion is something that most IDE's now come with so what you are after is already available...
That being said, what I would try would be to go over the PHP API and construct a Suffix tree. This type of tree usually allow for a fast way to look for a given word. Once you index the API, you would also add in any other variable the user adds while he/she is performing the actual programming.
You could kick the search automatically in your suffix tree after the user has entered the 3rd letter, or maybe provide means for the user to activate it manually, like the Ctrl-Space keyboard most IDE's (Visual Studio, Netbeans, Eclipse, etc) have.
Note that this could get tricky, since you might want to select the appropriate variable type.

Searching the name of web pages according to the word entered in a textbox

I have a textbox and a button in one page.I want to enter a word in the textbox and click the button. After clicking the button I want to display the name of the web pages containing the word entered in the textbox. So please tell me how to do it? I am using C#.
So you want to create a search engine internal to your website. There are a couple of different options
You can use something like google custom search which requires no coding and uses the google technology which I think we all agree does a pretty good job compared to other search engines. More information at http://www.google.com/cse/
Or you can implement it in .net which I will try to give some pointers about below.
A search engine in general exists out of (some of) the following parts:
a index which is searched against
a query system which allows searches to be specified and results shown
a way to get documents into the index like a crawler or some event thats handled when the documents are created/published/updated.
These are non trivial things to create especially if you want a rich feature set like stemming (returning documents containing plural forms of search terms), highlighting results, indexing different document formats like pdf, rtf, html etc... so you want to use something already made for this purpose. This would only leave the task of connecting and orchestrating the different parts, writing the flow control logic.
You could use Lucene.net a opensource project with a lot of features. http://usoniandream.blogspot.com/2007/10/tutorial-implementing-lucenenet-search.html explains how to get started with it.
The other option is Microsoft indexing service which comes with windows but I would advice against it since it's difficult to tweak to work like you want and the results are sub-optimal in my opinion.
You are going to need some sort of backing store, and full text indexing. To the best of my knowledge, C# alone is not enough.

Syntax Highlighting in a ListBox

I've searched the web and I can't seem to find anything that will work for me. I've seen plenty of discussion, and even some fairly extensible open-source tools, for code editors that provide line numbers and syntax highlighting.
Here's my dilemma...
I'm working on a "digital code review" project in C#.NET that allows users to specify source files, add them to a particular session, and other users can make comments and line references to the files being reviewed.
Basic requirements:
Must be written in C#.NET
I don't need to be able to edit the text in the text box
Users need to be able to select a line (or multiple lines), to make line references.
It seems to me that I need some fancy implementation of a ListBox control (not a drop-down list) that has some OwnerDraw capabilities to add line numbers and syntax highlighting. Unfortunately, I haven't had any luck putting it together myself, and I can't seem to find a control that's already been written or a reference on how I might be able to accomplish this.
Any suggestions??
I suggest to try ScintillaNet. It has syntax highlight and line numbers (and so much more). However you cannot select more lines only one selection at the time.
I would use a text box control for this, just make it read only and put the line numbers in when you load it. Just a quick question, when you say:
Users need to be able to select a line (or multiple lines), to make line references.
Is this in a web app? How do the users indicate that they want to create a reference (some button somewhere?). Easier to do on windows with a context menu. Where does the user reference to the code go, how does it appear to other users viewing the code?

Categories