Author Topic: Print properties of an object  (Read 4556 times)

StridingDragon

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Print properties of an object
« on: June 13, 2013, 08:08:38 PM »
Does anyone here have any helper functions or classes they'd like to share that would allow to print the properties of any C# object? Since Mono's debug capabilities are so limited, it seems almost imperative to have something that allows you to look at the contents of an object during run time but I can't seem to find any decent function to do that.

Any help would be very much appreciated.

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: Print properties of an object
« Reply #1 on: June 14, 2013, 02:54:00 AM »
I found somting you could use

http://stackoverflow.com/questions/737151/how-to-get-the-list-of-properties-of-class

My experiment (I did not get the value , but the name of the property)

  1.         string []proppertys = new string[100];
  2.                
  3.                 int i = 0;
  4.                 foreach(System.Reflection.PropertyInfo mypropperty in this.GetType().GetProperties())
  5.                 {
  6.                         proppertys[i] = mypropperty.Name + " : " + mypropperty.GetValue(this,System.Reflection.BindingFlags.GetProperty());
  7.                                
  8.                         Debug.LogWarning(proppertys[i]);
  9.                                
  10.                                 i++;
  11.                 }
  12.                
  13.                
  14.                
  15.