Mandar's blog about .Net & PHP Web Development

  • Archive
  • RSS

.NET Tip : How to print all property names & values of .NET class ?

Heres .net code

public static void PrintClassMemberValues(object source, System.IO.TextWriter tw)
{
Type sourceType = source.GetType();
tw.WriteLine(“——————- ” + sourceType.Name + ” ——————- “);
foreach (PropertyInfo sourceProperty in sourceType.GetProperties())
{
tw.WriteLine(sourceProperty.Name + “=” + sourceProperty.GetValue(source, null));
}
tw.WriteLine(“——————-“);
}

Usage :

MyClass helloClass = new MyClass();

helloClass.Name=”Test”;

helloClass.ID=1234;

PrintClassMemberValues(helloClass,Console.Out);


  • 2 years ago
  • Permalink
  • Share
    Tweet
← Previous • Next →

Get 2GB Free Cloud storage

>> Download dropbox


About

I am programmer from London specializing in web based technologies, startups and web 2.0 related stuff.

My Startup

WealthBird

Available for Freelancing work

I am available for .NET contracting work in & around London. Drop me a mail : mandarp1979 at gmail.com

  • RSS
  • Random
  • Archive
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr