Looking to the previous post, with an excellent advice from Pedro Lamas (Thanks a lot!!!), the source code now goes like this...
Now, making use of reflection and extension method together, we have the possibility to use the GetPropertiesAndValues method at any object inside the program scope.
In other words, you can use GetPropertiesAndValues for every object (like an instance of a class) present in your program, getting the returned string "My object Properties & Values \n\nPropName: PropValue\n (etc.)"
For instance:
References:
http://stackoverflow.com/questions/1447308/enumerating-through-an-objects-properties-string-in-c
http://www.developer.com/net/csharp/article.php/3592216/Using-the-New-Extension-Methods-Feature-in-C-30.htm
Showing posts with label reflection. Show all posts
Showing posts with label reflection. Show all posts
Wednesday, February 02, 2011
Tuesday, February 01, 2011
C# - Get All Properties From Class Or Type
Have you ever try to get all properties from a Class/Type on the fly? the next snippet demonstrates how to query the class instance and retrieve the properties names and their respective values.
It goes like this...
This way you have a string returned like "propName1: valueProp1\n" and so on.
Reference:
Subscribe to:
Posts (Atom)


