using System.Collections.Generic;
using System.Collections;
public static void Main()
Reference = $"{nameof(Foo)}.{nameof(Foo.Reference)} Value",
Company = new CompanyModel
Name = $"{nameof(Foo)}.{nameof(CompanyModel)}.{nameof(CompanyModel.Name)} Value",
CallData = new CallDataModel
Item = Enumerable.Range(1,10).Select(x=> new CallModel{Name= $"{nameof(Foo)}.{nameof(CallModel)}.{nameof(CallModel.Name)} {x}",Value= x})
private static void GetProperties<T>(T obj)
Type objType = obj.GetType();
PropertyInfo[] properties = obj.GetType().GetProperties();
foreach (PropertyInfo property in properties)
if (property.IsEnumerable())
if(property.GetValue(obj,null) is IEnumerable elems)
foreach (var item in elems)
var propValue = property.GetValue(obj, null);
if (property.PropertyType.Assembly == objType.Assembly)
GetProperties(propValue);
Console.WriteLine($"{property.Name} = {propValue}");
public string Reference { get; set; }
public CompanyModel Company { get; set; }
public CallDataModel CallData { get; set; }
public class CompanyModel
public string Name { get; set; }
public class CallDataModel
public IEnumerable<CallModel> Item { get; set; }
public string Name { get; set; }
public int Value { get; set; }
public static class Extensions
public static bool IsEnumerable(this PropertyInfo propertyInfo)
if(!propertyInfo.PropertyType.GetInterfaces().Contains(typeof(IEnumerable)) )
return propertyInfo.PropertyType != typeof(String);