I was doing a code review and I wanted to know that if there is a way to find out which all methods are being used in a program that belong to a particular namespace. For example, in the image below:
you can see the .NET Framework Class Library namespaces that are being declared in this particular scenario.
My question is: How can I find out where a particular method of a particular namespace is being used in the program. In the image below:
you can see that when I hover on ConfigurationManager, it tells me that it belongs to the System.Configuration namespace.
I wanted to know if there are way to find a list of all methods that belong to a particular namespace in a .cs file?
Thanks in advance.
If you have ReSharper, you can put the cursor on the word "using" in the using statement, and then right-click and "Find Usages". This will show all usages of methods, classes etc in the namespace, as you require. Make sure the cursor is on "using" - if it's on the namespace name itself, then it will find all of the using statements for that namespace instead.
for my experience and if i understand you correctly,
To find where a method is being used, u can right click on the method and click "Find all References" Like this
And to know what methods are available in a cs, i only know this way
Related
I'm trying to create a crud web app. I'm getting errors about the name space, which I can't figure out (sure it's something simple!) What does the type or namespace could not be found mean? It's only on pages related to the database. Or is there a way to link the sqlite database without a migration folder - ProjectContext file?
This class looks like it exists but in a different namespace to the one the controller is in. You will either need to provide a full refeerence to it's location:
Place1.Place2.ProjectContext
or a using statment at the top.
using Place1.Place2;
Visual studio has a shortcut to help you track down classes like this, right click on the problem class and click "Quick actions and Refactoring..." and you may be presented with an option to either insert a 'using' statement at the top or use a full reference.
Quick actions and Refactoring
How do I refactor the namespace of components that use dotted notation in my Visual Studio 2010 Pro solutions (C#)?
I have tried selecting Refactor->Rename or pressing F2 with the cursor at the head of the namespace string, but this only works for the first part of a dotted namespace string (e.g. "a.b.c.d" selects "a").
I've also tried highlighting the entire namespace and selecting Refactor->Rename but I'm presented with a dialog message that says: "Please select a symbol to be renamed."
Any help?
VS doesn't have anything built into it for this (yet).
ReSharper can do it for you:
For this i removed the .Entities from the namespace (sorry, i had to disguise some namespaces there, but you get the idea).
If you don't want to download a trial version of ReSharper and do it (hey, you may end up liking it!), then your best option is to ensure you have all your projects loaded, change the namespace at the top of the relevant class files, then attempt a recompile. All the faulty declarations or namespce useage will now show up in the Error List window - except for some XAML ones. (Some XAML useages will show up straight away, others will only show up at run time. You should be able to do a global search + replace on .xaml files only, this is reasonably safe, but make sure you have your files either backed up or managed in a source control repository).
Wouldn't find/replace do this for you? Search for namespace a.b.c.d, replace with namespace d.e.f; find using a.b.c.d, replace with using d.e.f.
I want to do this:
enum Foo
{
[Display="Item One"]
ItemOne,
}
So that Intellisense will display it like in the attribute instead of the actual name.
I know it's possible, I've seen it before.
Well you could provide XML documentation:
enum Foo
{
/// <summary>Item One</summary>
ItemOne
}
I'm not sure whether that's quite what you were thinking of, but here's an example of what it looks like in VS 2010:
Note that I'm assuming you mean from the code editor... if you mean within a property editor, that could be something entirely different, e.g. DisplayNameAttribute (although that's meant for properties, events or methods).
If you know an example of what you want within the framework, we may be able to help more.
As a note... if you are building a .dll that is to be referenced by another application, just writing a summary will not allow the text to show up in intellisense for the referencing application. To accomplish this, you must deploy the XML documentation file as well, which requires a re-compiled version of the same .dll.
To do this (in VS2008 anyways), go into the Properties of your project, click the Build tab, click the checkbox at the bottom next to 'XML documentation file:', rebuild the application, and now you have the files needed to make it work.
I'm currently using a library that implements Menus and ContextMenus for Silverlight 3 and 4. This library defines a MenuItem class in the System.Windows.Controls namespace.
No problems with SL3 because there is no MenuItem class elsewhere in the Silverlight class library; but now I need to use another control in a Silverlight 4 Toolkit assembly and the toolkit now defines a System.Windows.Controls.MenuItem in this same assembly !
So I need a way to indicate to the compiler that I want to use the System.Windows.Controls.MenuItem from my old assembly and not the one in the toolkit 4 assembly.
The solution seems the "external aliases" features.
I can tweak the files I write myself with external aliases but how to indicate to the code generator, the one that generates ".g.i.cs" files from XAML, wich assembly, more exactly which aliases, to use ?
By default it always generates System.Windows.Controls.MenuItem variables in the ".g.i.cs" files, and of course without aliases the C# compiler is unable to know which assembly to use.
I'm using VS 2010 Professional but I haven't been able to find an option to change this behaviour.
Thanks in advance.
I'm afraid the only way around this is to rip the contents of the .g.i.cs file and move it your .cs file, tweak it up with your aliases, remove the partial keyword and then remove the x:Class from the Xaml.
Upside is the designer will still work. The downside is you need create any new control fields yourself and add the FindName code to the copy of InitializeComponent you now have in your .cs. Personally I quite like this, there are plenty of reasons to give an element a name other than it needing to be a field in the class (binding and animation being two of them). Its annoying that fields are automatically created and precious load time devoted to finding and assigning when they're never used.
Finally I've found a workaround :
I've created a library project that wraps the types from the menus library.
For instance :
namespace Alias
{
public class MenuItem : System.Windows.Controls.MenuItem
{
}
}
I then reference this project from my real project and can use the type through their "new" namespace "Alias".
It's a kind of "heavy alias" but seems to work.
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.