using System.Collections.Generic;
using System.ComponentModel;
public string Make { get; set; }
public IList<SeatBelt> SeatBelts { get; set; }
public SeatBeltz SeatBelt { get; set; }
public InstanceStatusEnum? Status {get; set;}
public bool Secure {get;set;}
public int Test {get; set;}
public DateTime Test2 {get; set;}
public bool Secure {get;set;}
public int Test {get; set;}
public DateTime Testz {get; set;}
public enum InstanceStatusEnum
[Description("Em Andamento")]
[Description("Concluído")]
[Description("Cancelado")]
public static void Main()
Console.WriteLine(nameof(Car.SeatBelt.Secure));
var car = new Car { Status = null, Make = "Ford2", SeatBelts = new List<SeatBelt> { new SeatBelt { Secure = true, Test = 10, Test2 = DateTime.Now} }, SeatBelt = new SeatBeltz { Secure = true, Test = 10, Testz = DateTime.Now}};
string propertyRawName = "Status";
var propertyNames = propertyRawName.Split('.');
foreach(var property in propertyNames) {
Console.WriteLine(property);
var propertyValue = GetPropertyValue(propertyNames, car, 0).ToString();
Console.WriteLine($"O valor da propriedade {propertyRawName} é {propertyValue}");
private static object GetPropertyValue<T>(string[] propertyNames, T entity, int index)
string? currentPropertyName = string.Empty;
Console.WriteLine($"{propertyNames.Length} - {index + 1}");
currentPropertyName = propertyNames?.ElementAtOrDefault(index);
if (currentPropertyName is null) return entity;
var propertyInfo = entity?.GetType().GetProperty(currentPropertyName);
var propertyValue = propertyInfo?.GetValue(entity);
if (propertyValue is null) return string.Empty;
if (propertyInfo.PropertyType.IsEnum)
Enum enumValue = (Enum)propertyValue;
return enumValue.GetEnumDescriptionSLA();
if (propertyNames.Length == index + 1) {
Console.WriteLine("asda");
if(!propertyInfo.PropertyType.IsSerializable)
return JsonSerializer.Serialize(propertyValue);
return GetPropertyValue(propertyNames, propertyValue, index + 1);
public static class Test {
public static string GetEnumDescriptionSLA(this Enum value)
var fieldInfo = value.GetType().GetField(value.ToString());
var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
return attributes.Length > 0
? attributes[0].Description