C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
listing members of a class Posted by VanilleBert on 5 Jan 2006 at 7:52 AM
Hi,

I ask for a methode to listing members of a class. The names, types and values of a member of a class should be readable.

Is there any possibility to read this information at runtime and put it into a string?

Thx for response

Bert

PS:
Example:
class MyClass
{
    public int Member1;
    public OtherClass Member2;
    public string Member3;
    
    public MyClass();
    public int Member4(int arg);
}
...
Console.WriteLine(ListMembersOf(MyClass));

Wished Result:
int Member1 = 3
System.FavouriteNamespace.OtherClass Member2 = xyz
string Member3 = String of Member3
MyClass()
int Member4(int arg)

Report
Re: listing members of a class Posted by iwilld0it on 6 Jan 2006 at 8:59 PM
Look into the Systsem.Reflection namespace.

As a hint, all objects inherit from the base System.Object class which has a GetType() function.

Type typ = myObj.GetType();

This "Type" class has many functions for displaying the list of functions, properties, etc ... that an object supports.


: Hi,
:
: I ask for a methode to listing members of a class. The names, types and values of a member of a class should be readable.
:
: Is there any possibility to read this information at runtime and put it into a string?
:
: Thx for response
:
: Bert
:
: PS:
: Example:
:
: class MyClass
: {
:     public int Member1;
:     public OtherClass Member2;
:     public string Member3;
:     
:     public MyClass();
:     public int Member4(int arg);
: }
: ...
: Console.WriteLine(ListMembersOf(MyClass));
: 

: Wished Result:
:
: int Member1 = 3
: System.FavouriteNamespace.OtherClass Member2 = xyz
: string Member3 = String of Member3
: MyClass()
: int Member4(int arg)
: 

:

Report
Re: listing members of a class Posted by VanilleBert on 7 Jan 2006 at 4:53 AM
: Look into the System.Reflection namespace.
:
: As a hint, all objects inherit from the base System.Object class which has a GetType() function.
:
: Type typ = myObj.GetType();
:
: This "Type" class has many functions for displaying the list of functions, properties, etc ... that an object supports.

Thx for that simple way.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.