I have 3 classes which form an object like this :
public class Pax
{
public PaxType PaxType { get; set; }
public int Age { get; set; }
public string Title { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class Room
{
public Room()
{
Paxes = new List<Pax>();
}
public List<Pax> Paxes { get; set; }
}
public class AvaliableHotelRequest
{
public AvaliableHotelRequest()
{
Rooms = new List<Room>();
}
public string Method { get; set; }
public string ApiKey { get; set; }
public string DestinationId { get; set; }
public DateTime CheckIn { get; set; }
public DateTime CheckOut { get; set; }
public string Currency { get; set; }
public string ClientNationality { get; set; }
public bool OnRequest { get; set; }
public List<Room> Rooms { get; set; }
}
I need to use reflection to get following object in to an string like this:
var pax1 = new Pax()
{
PaxType = PaxType.Adult
};
var pax2 = new Pax()
{
PaxType = PaxType.Adult
};
var pax3 = new Pax()
{
PaxType = PaxType.Children,
Age = 5
};
var paxList1 = new List<Pax> {pax1, pax2, pax3};
var paxList2 = new List<Pax> { pax2, pax3 };
var rooms = new List<Room>(){new Room(){Paxes = paxList1}, new Room(){Paxes = paxList2}};
var request = new AvaliableHotelRequest()
{
ApiKey = "jhjfjdshsfjkhjhfsdfks",
CheckIn = DateTime.Now,
CheckOut = DateTime.Now.AddDays(5),
ClientNationality = "AU",
Currency = "EUR",
DestinationId = "LD6J",
Method = "getAvailableHotel",
OnRequest = false,
Rooms = rooms
};
output : ?method=getAvailableHotel&apiKey=kggdjjgdhgkjghkgjghkjdg&destinationId=LD6J&checkIn=2011-04-20&checkOut=2011-04-24¤cy=EUR&clientNationality=UK&onRequest=false&rooms[0][0][paxType]=Adult&rooms[0][1][paxType]=Adult&rooms[0][2][paxType]=Child&rooms[0][2][age]=6&rooms[1][0][paxType]=Adult&rooms[1][1][paxType]=Adult&rooms[1][2][paxType]=Child&rooms[1][2][age]=8
Been trying different ways but could not get passed this issue. I would be thankful if you help me.
I found this Recursively Get Properties & Child Properties Of An Object but its just listing the properties not the values. Thanks.