How to export class names,method names given a namespace in c# without it being a part of that namespace/code to preferrably a txt file. The code should not be a part of the code whose classes, method names are to be retrieved.
Asked
Active
Viewed 1,504 times
0
-
2Could you give us some code to see what you tried? – Carlos Landeras May 07 '13 at 08:29
-
No am completely blank. Have not started to code. – cooltoad May 07 '13 at 08:31
-
Did you do any research on this topic? – Daniel Hilgarth May 07 '13 at 08:32
-
found some pages that instruct to use reflection, assemblies. But couldn't get to understand them. – cooltoad May 07 '13 at 08:33
-
i guess a more elaborate reponse in this link would have helped. http://stackoverflow.com/questions/2318928/how-to-get-all-classes-in-current-project-using-reflection – cooltoad May 07 '13 at 08:36
1 Answers
1
Just reflection:
string ns = "System.Text";
var types = from asm in AppDomain.CurrentDomain.GetAssemblies()
from type in asm.GetTypes()
where type.Namespace == ns
orderby type.Name
select type;
foreach(var type in types)
{
Console.WriteLine("{0} ({1})", type.Name, type.Assembly.FullName);
// and list the methods for each type...
foreach (var method in type.GetMethods().OrderBy(x => x.Name))
{
Console.WriteLine("\t{0}", method.Name);
}
}
Note that in the above I'm looking in all the loaded assemblies in the current app-domain; you can also just look in an individual assembly if appropriate.

Marc Gravell
- 1,026,079
- 266
- 2,566
- 2,900
-
This code works as intended. Thanks a lot. Any leads on how to save it as a text file? – cooltoad May 07 '13 at 11:55
-
`using(var output = File.CreateText()) {...}` and write to `output` instead of `Console` ? – Marc Gravell May 07 '13 at 11:56
-
-
Since this answer explained and worked with the "System.Text" namespace i added reference to another project and gave its namesapce in ns. But not working. where am i going wrong?? – cooltoad May 08 '13 at 05:24
-
@cooltoad to use an individual assembly you could start with `from type in typeof(SomeTypeYouKnow).Assembly.GetTypes()`, where `SomeTypeYouKnow` is in the assembly you are talking about. The reason it isn't working currently is that nothing is *loading* the assembly you are talking about. The `typeof` will force it to be loaded. – Marc Gravell May 08 '13 at 06:30
-
I have exported it as a text file... But i also need to do the same in java. Any leads ? – cooltoad May 14 '13 at 08:01