public static void Main()
Console.WriteLine("Hello World");
var foo = GetPropertyValue(obj, "Foo.Bar.Baz");
public static string? GetPropertyValue(object source, string propertyName)
return GetInnerProp(source, propertyName) as string;
private static object GetInnerProp(object source, string propertyName)
if (propertyName.Contains('.'))
var propertyNames = propertyName.Split(".");
var firstProp = propertyNames.First();
var newSource = source.GetType().GetProperty(firstProp).GetValue(source, null);
var rest = string.Join(".", propertyNames.Skip(1));
return GetInnerProp(newSource, rest);
return source.GetType().GetProperty(propertyName).GetValue(source, null);