예제 #1
0
파일: PKM.cs 프로젝트: tkfltkgk/PKHeX
        /// <summary>
        /// Applies all shared properties from <see cref="Source"/> to <see cref="Destination"/>.
        /// </summary>
        /// <param name="Source"><see cref="PKM"/> that supplies property values.</param>
        /// <param name="Destination"><see cref="PKM"/> that receives property values.</param>
        protected void TransferPropertiesWithReflection(PKM Source, PKM Destination)
        {
            var SourceProperties      = ReflectUtil.getPropertiesCanWritePublic(Source.GetType());
            var DestinationProperties = ReflectUtil.getPropertiesCanWritePublic(Destination.GetType());

            // Skip Data property when applying all individual properties. Let the setters do the updates for Data.
            foreach (string property in SourceProperties.Intersect(DestinationProperties).Where(prop => prop != nameof(Data)))
            {
                var prop = ReflectUtil.GetValue(this, property);
                if (prop != null)
                {
                    ReflectUtil.SetValue(Destination, property, prop);
                }
            }
        }
예제 #2
0
        protected void TransferPropertiesWithReflection(PKM Source, PKM Destination)
        {
            var SourceProperties      = ReflectUtil.getPropertiesCanWritePublic(Source.GetType());
            var DestinationProperties = ReflectUtil.getPropertiesCanWritePublic(Destination.GetType());

            foreach (string property in SourceProperties.Intersect(DestinationProperties).Where(prop => prop != nameof(Data)))
            {
                var prop = ReflectUtil.GetValue(this, property);
                if (prop == null)
                {
                    continue;
                }
                ReflectUtil.SetValue(Destination, property, prop);
            }
        }