listing members of a class

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:
[code]
class MyClass
{
public int Member1;
public OtherClass Member2;
public string Member3;

public MyClass();
public int Member4(int arg);
}
...
Console.WriteLine(ListMembersOf(MyClass));
[/code]
Wished Result:
[code]
int Member1 = 3
System.FavouriteNamespace.OtherClass Member2 = xyz
string Member3 = String of Member3
MyClass()
int Member4(int arg)
[/code]

Comments

  • 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:
    : [code]
    : class MyClass
    : {
    : public int Member1;
    : public OtherClass Member2;
    : public string Member3;
    :
    : public MyClass();
    : public int Member4(int arg);
    : }
    : ...
    : Console.WriteLine(ListMembersOf(MyClass));
    : [/code]
    : Wished Result:
    : [code]
    : int Member1 = 3
    : System.FavouriteNamespace.OtherClass Member2 = xyz
    : string Member3 = String of Member3
    : MyClass()
    : int Member4(int arg)
    : [/code]
    :

  • : 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.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories