public Company(string name, string address, string phone, string fax, string website, Manager man) { this.Name = name; this.Address = address; this.Phone = phone; this.Fax = fax; this.Website = website; this.Manager = man; }
public static void PrintCompany() { // All members in company are public can be accessed by calling member Company comp = new Company(); // Manager has private members that must be accessed through getter/setter // Note: used the same way... // Can initialize members of manager through constructor or assign dynamically Manager man = new Manager(); Console.WriteLine("What is the name of your company?"); comp.Name = Console.ReadLine(); Console.WriteLine("What is the address of your company?"); comp.Address = Console.ReadLine(); Console.WriteLine("What is the phone number of your company?"); comp.Phone = Console.ReadLine(); Console.WriteLine("What is the fax of your company?"); comp.Fax = Console.ReadLine(); Console.WriteLine("What is the website of your company?"); comp.Website = Console.ReadLine(); Console.WriteLine("What is the first name of your manager?"); Console.WriteLine("What is the first name of your manager?"); man.FName = Console.ReadLine(); Console.WriteLine("What is the last name is your manager?"); man.LName = Console.ReadLine(); Console.WriteLine("What is your manager's phone number?"); man.Phone = Console.ReadLine(); comp.Manager = man; // Reflection enables you to discover an object's properties, methods, events and properties values at run-time. // Reflection can give you a full mapping of an object (well, it's public data). var companyProperties = comp.GetType().GetProperties(); var managerProperties = comp.Manager.GetType().GetProperties(); foreach(var prop in companyProperties) { Console.WriteLine(string.Format("{0} : {1}", prop.Name, prop.GetValue(comp, null))); } foreach(var prop in managerProperties) { Console.WriteLine(string.Format("{0} : {1}", prop.Name, prop.GetValue(comp, null))); } }