using System.ComponentModel;
using System.Linq;
using Dapper;

namespace Valg.EVA.Skanning.Repositories
{
    public static class DynamicExtensions
    {
        public static DynamicParameters ToDynamicParameters(this object value, params string[] excludeProperties)
        {
            var parameters = new DynamicParameters();

            foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(value.GetType()))
            {
                if (excludeProperties.Contains(property.Name))
                    continue;

                parameters.Add('@' + property.Name, property.GetValue(value));
            }


            return parameters;
        }
    }
}
