Esempio n. 1
0
        public object Clone()
        {
            Assignable r = (Assignable)Activator.CreateInstance(GetType());

            r.Assign(this);
            return(r);
        }
Esempio n. 2
0
        /// <summary>
        /// Copia as propriedades de outra instância da mesma classe
        /// </summary>
        /// <param name="another"></param>
        /// <returns></returns>
        public bool Assign(Assignable another)
        {
            if (another == null || this.GetType() != another.GetType())
            {
                return(false);
            }

            var thispi = GetType().GetProperties();

            try
            {
                foreach (var pi in thispi)
                {
                    if (pi.CanWrite)
                    {
                        pi.SetValue(this, pi.GetValue(another));
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }