Tipalti interview question

Advanced Hands-on: Implement a utility that will use .NET reflection APIs to print “simple” objects. “Simple” objects are defined as follows: They have only public properties Each property can be of the following types: Primitive (e.g. int), or string Object – assume that that object is also a "simple" object Array of “simple” objects The program should navigate the object structure and print the structure. Here's an example: class Name { public string FirstName {get; set;} public string LastName {get; set;} } class Pet { public string Nickname {get; set;} } class Person { public int Age {get; set;} public Name Name {get; set;} public Pet[] Pets {get; set;} } Name n = new Name(); n.FirstName = "John"; n.LastName = "Doe"; Pet[] pets = new Pet[] {new Pet {Nickname="Rocky"}, new Pet {Nickname="Louie"}}; Person p = new Person(); p.Age = 55; p.Name = n; p.Pets = pets; The output of your utility when run on instance p above should be something like this: Object of Class "Person" ---------------------------------------- Age = 55 Name = Object of Class "Name" ---------------------------------- FirstName = "John" LastName = "Doe" Pets = [ Object of Class "Pet" ---------------------------------- Nickname = “Rocky” Object of Class "Pet" ---------------------------------- Nickname = “Louie” ] Keep the indentation of inner objects as in the example. General guidelines: You can assume your input contains only “Simple” objects as defined above Total time for the exercise is 1 hour, please do not exceed the allocated time In case you are not familiar with .NET reflection APIs please specify that in a comment. Hint: call the GetType() method of Object which is available on the object you are trying to print in order to start accessing the class metadata Make sure exceptions are handled properly Make sure the API to use this utility is convenient to use You cannot use ChatGPT or other generative AI tool, you may use the Google/MSDN website for help. You cannot use libraries outside .NET. or any other external code. Write the code as though you are writing production code.