Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

List of functions in a class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marco Balk - 27 Feb 2008 14:07 GMT
I want to create my own ToString() function, which outputs a summary
of a class.
How can I retrieve a list of functions in a class?

I want to try to get the following output (this will be a nice HTML
list):

Class foo
- functions:
--- static function static_foo()
--- public function public_foo()
--- private function private_foo()
- variables
--- public int X
--- public string Y
--- protected bool Z
- properties
--- public string Name
--- public int Age

Code example:

foo objFoo = new foo();
Response.Write(objFoo.ToString());

Thanks in advance!!!
Jon Skeet [C# MVP] - 27 Feb 2008 14:12 GMT
> I want to create my own ToString() function, which outputs a summary
> of a class.
[quoted text clipped - 22 lines]
>
> Thanks in advance!!!

Well, at that point you're really writing out information about the
*type* rather than about the object itself (unless you include the
values of the properties etc).

There are various methods on Type which return the fields, methods,
properties etc. You'll need to think about whether you want to show
inherited members as well.

Jon
Marco Balk - 27 Feb 2008 14:35 GMT
> > I want to create my own ToString() function, which outputs a summary
> > of a class.
[quoted text clipped - 32 lines]
>
> Jon

Thanks Jon.

This is just what I need.
I guess there's no way to display private or protected Members?
Jon Skeet [C# MVP] - 27 Feb 2008 14:55 GMT
<snip>

> This is just what I need.
> I guess there's no way to display private or protected Members?

Yes, you just need to specify BindingFlags.NonPublic.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.