This project is read-only.
1

Closed

Property copying bug

description

Hi,
I've downloaded you lib and I'm testing it - so far it seems cool, and so far I've found a minor and a major bug, both in the same method (pasting fixed version):
        /// <summary>
        /// Copies the values of all primitive (non-navigation) properties on source to destination.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        internal static void CopyPublicPrimitivePropertyValues(object source, object destination)
        {
            Contract.Requires<ArgumentNullException>(source != null);
            Contract.Requires<ArgumentNullException>(destination != null);

            var destinationType = destination.GetType();
            if (destinationType.BaseType != null && destinationType.Namespace == "System.Data.Entity.DynamicProxies")
            {
                destinationType = destinationType.BaseType;
            }

            Type sourceType = source.GetType();
            if (! Object.ReferenceEquals(sourceType, destinationType))
            {
                throw new ArgumentException(string.Format("Source type '{0}' and destination type '{1}' must match.", sourceType.FullName, destination.GetType().FullName));
            }

            foreach (PropertyInfo property in sourceType.GetProperties(BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance))
            {
                if (IsEdmPrimitiveType(property.PropertyType))
                {
                    object propertyValue = property.GetValue(source);
                    property.SetValue(destination, propertyValue);
                }
            }
        }
More may come ;).

Regards,
Pawel

comments