xyz
xyz

Reputation:

How do I fetch all methods from a given namespace?

I want all the Method-ClassName from namespace

like i have system.windows.Forms

wehen in visual studio we rigt system.windows.Forms. it will suggest box of all the related method,class,enum extra

i need to fetch the same ,how can i do that in C#

Upvotes: 0

Views: 338

Answers (2)

Jon Skeet
Jon Skeet

Reputation: 1504062

For a start, there are no methods in a namespace - only types.

To get all the types from one namespace within a particular assembly, you can use (assuming .NET 3.5 for the LINQ bit) Assembly.GetTypes:

var types = assembly.GetTypes().Where(type => type.Namespace == desiredNamespace);

Types can be spread across multiple assemblies, however.

Once you've got a type, you can use Type.GetMethods to retrieve the methods available. Use appropriate BindingFlags to get static/instance, public/non-public methods etc.

If this doesn't help, please clarify the question.

Upvotes: 5

ChrisW
ChrisW

Reputation: 56123

This kind of functionality is called "reflection".

http://www.codersource.net/published/view/291/reflection_in.aspx for example (which I found by Googling for 'reflection' and 'C#') mentions relevent .NET API methods which you invoke from C#.

Upvotes: 0

Related Questions