using FastMember;
using System.Collections.Generic;
using System.Net.Http;

namespace Knoks.Test.Integrations.Api.Tools
{
    public static class Extentios
    {
        public static FormUrlEncodedContent GetFormUrlEncodedContent(this object obj)
        {
            var kvp = new Dictionary<string, string>();
            var typeAccessor = TypeAccessor.Create(obj.GetType());

            foreach (var member in typeAccessor.GetMembers())
            {
                var memberValue = typeAccessor[obj, member.Name];
                if (memberValue != null)
                    kvp[member.Name] = memberValue.ToString();
            }

            return new FormUrlEncodedContent(kvp);
        }
    }
}

