Extensions/ObjectExtensions.cs
using System.Collections.Generic;
using System.Linq;

namespace BetterUI.Extensions;

public static class ObjectExtensions
{
	/// <summary>
	/// Converts an object to a dictionary of its properties.
	/// </summary>
	/// <param name="value">The object to convert.</param>
	/// <returns>A dictionary of the object's properties.</returns>
	public static Dictionary<string, object> ToDictionary( this object value )
	{
		var props = TypeLibrary.GetPropertyDescriptions( value, true );
		return props.ToDictionary( prop => prop.Name, prop => prop.GetValue( value ) );
	}
}