using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace WinGreed
{
    public static class ControlExtensions
    {
        public static T Clone<T>(this T controlToClone)
            where T : Control
        {
            PropertyInfo[] controlProperties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);

            T instance = Activator.CreateInstance<T>();

            foreach (PropertyInfo propInfo in controlProperties)
            {
                if (propInfo.CanWrite)
                {
                    //Debug.WriteLine($"Can write :{propInfo.CanWrite} Name : {propInfo.Name}");
                    if (propInfo.Name == "Image")
                    {
                        //switch (switch_on)
                        //{
                        //    default:
                        //}
                    }
                    else
                    {
                        if (propInfo.Name != "WindowTarget")
                            propInfo.SetValue(instance, propInfo.GetValue(controlToClone, null), null);
                    }
     
                }
            }

            return instance;
        }
    }
}
