using System.Collections.Generic;
public static void Main()
AddressDetail = new List<Address>() {
new Address {Street = "First St.",
CountryDetail = new Country {
new Address {Street = "abc.",
CountryDetail = new Country {
var nested1 = GetPropertyValue(p, "Name");
var nested2 = GetPropertyValue(p, "AddressDetail.Street");
var nested3 = GetPropertyValue(p, "AddressDetail.CountryDetail.CountryName");
Console.WriteLine(nested1);
Console.WriteLine(nested2);
Console.WriteLine(nested3);
public static object GetPropertyValue(object src, string propName)
if (src == null) throw new ArgumentException("Value cannot be null.", "src");
if (propName == null) throw new ArgumentException("Value cannot be null.", "propName");
if(propName.Contains("."))
var temp = propName.Split(new char[] { '.' }, 2);
return GetPropertyValue(GetPropertyValue(src, temp[0]), temp[1]);
if (src.GetType().Name == "List`1")
List<Object> collection = new List<Object>((IEnumerable<Object>)src);
var prop2 = collection[0].GetType().GetProperty(propName);
return prop2 != null ? prop2.GetValue(collection[0], null) : null;
var prop = src.GetType().GetProperty(propName);
return prop != null ? prop.GetValue(src, null) : null;
public string Name { get; set;}
public List<Address> AddressDetail { get; set;}
public string Street { get; set;}
public Country CountryDetail { get; set;}
public string CountryName { get; set;}