using System.Collections;
using System.Collections.Generic;
public static void Main()
propClass MyClass = new propClass();
MyClass.service_name = "test";
List<string> myColors = new List<string>{"blue", "green" , "red"};
MyClass.colors = myColors;
PrintProperties(MyClass, 1);
public string service_name { get; set; }
public int code { get; set; }
public decimal version { get; set; }
public List<string> colors { get;set; }
List<string> colors = new List<string>();
public static void PrintProperties(object obj, int indent = 1)
string indentString = new string (' ', indent);
Type objType = obj.GetType ();
PropertyInfo[] properties = objType.GetProperties ();
foreach ( PropertyInfo property in properties )
object propValue = property.GetValue(obj,null);
var elems = propValue as IList;
Console.WriteLine("{0}{1}:", indentString, property.Name);
foreach ( var item in elems )
Console.WriteLine("{0}{1}",new string (' ', indent+2),item);
if ( property.PropertyType.Assembly == objType.Assembly )
Console.WriteLine("{0}{1}:", indentString, property.Name);
PrintProperties (propValue, indent + 2);
Console.WriteLine("{0}{1}: {2}", indentString, property.Name, propValue);