CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
using Faithlife.Reflection;
class Program
{
static void Main()
{
var dictionary = ConvertDtoToDictionary(new { one = 1, two = "II" });
foreach (var pair in dictionary)
Console.WriteLine(pair);
}
static IReadOnlyDictionary<string, object> ConvertDtoToDictionary(object dto) =>
DtoInfo.GetInfo(dto.GetType()).Properties.ToDictionary(x => x.Name, x => x.GetValue(dto));
}