Pages

Wednesday, February 02, 2011

C# - Get All Properties From Class Or Type [Reviewed]

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

No comments:

Post a Comment