using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; namespace CSharpConsoleApp { class First { public string FirstName { get; set; } public int Age { get; set; } } class Second { public string SecondName { get; set; } public First FirstObject { get; set; } } class Program { static void ReadProperties(object obj, string prefix = " ") { foreach (var prop in obj.GetType().GetProperties()) { if (prop.GetIndexParameters().Length == 0) { Console.WriteLine(prefix + prop.Name + ": " + prop.GetValue(obj, null)); if (!prop.PropertyType.IsPrimitive) { ReadProperties(prop.GetValue(obj, null), prefix + " "); } } } } static void Main(string[] args) { var sec = new Second { SecondName = "SecondName", FirstObject = new First { FirstName = "FirstName", Age = 12 } }; ReadProperties(sec); } } }