// <summary>
        // This method is called by a ComplexObject contained in this Entity
        // whenever a change has been made to a property of the
        // ComplexObject so that the change can be forwarded to the change tracker.
        // </summary>
        // <param name="entityMemberName"> The name of the top-level entity property that contains the ComplexObject that is calling this method. </param>
        // <param name="complexObject"> The instance of the ComplexObject on which the property is changing. </param>
        // <param name="complexMemberName"> The name of the changing property on complexObject. </param>
        internal override sealed void ReportComplexPropertyChanged(
            string entityMemberName, ComplexObject complexObject, string complexMemberName)
        {
            DebugCheck.NotNull(complexObject);
            DebugCheck.NotEmpty(complexMemberName);

            EntityChangeTracker.EntityComplexMemberChanged(entityMemberName, complexObject, complexMemberName);
        }
        // <summary>
        // This method is used to report all changes on this ComplexObject to its parent entity or ComplexObject
        // </summary>
        // <param name="entityMemberName"> Should be null in this method override. This is only relevant in Entity's implementation of this method, so it is unused here Instead of passing the most-derived property name up the hierarchy, we will always pass the current _parentPropertyName Once this gets up to the Entity, it will actually use the value that was passed in. </param>
        // <param name="complexObject"> The instance of the object on which the property is changing. </param>
        // <param name="complexMemberName"> The name of the changing property on complexObject. </param>
        internal override sealed void ReportComplexPropertyChanged(
            string entityMemberName, ComplexObject complexObject, string complexMemberName)
        {
            // entityMemberName is unused here because we just keep passing the current parent name up the hierarchy
            // This value is only used in the EntityObject override of this method

            DebugCheck.NotNull(complexObject);
            DebugCheck.NotEmpty(complexMemberName);

            if (null != _parent)
            {
                _parent.ReportComplexPropertyChanged(_parentPropertyName, complexObject, complexMemberName);
            }
        }
Exemple #3
0
 /// <summary>
 /// Fills the DTO from Complex object.
 /// </summary>
 /// <param name="fromComplex">
 /// The from Complex Object.
 /// </param>
 /// <param name="toDTO">
 /// To DTO.
 /// </param>
 public static void FillDTOFromComplexObject(ComplexObject fromComplex, IDTO toDTO)
 {
     FillData(toDTO, fromComplex, false);
 }
        /// <summary>
        /// This method is called by a ComplexObject contained in this Entity 
        /// whenever a change has been made to a property of the  
        /// ComplexObject so that the change can be forwarded to the change tracker.
        /// </summary>
        /// <param name="entityMemberName">
        /// The name of the top-level entity property that contains the ComplexObject that is calling this method.
        /// </param>
        /// <param name="complexObject">
        /// The instance of the ComplexObject on which the property is changing.
        /// </param>
        /// <param name="complexMemberName">
        /// The name of the changing property on complexObject.
        /// </param>        
        internal override sealed void ReportComplexPropertyChanged(
            string entityMemberName, ComplexObject complexObject, string complexMemberName)
        {
            Debug.Assert(complexObject != null, "invalid complexObject");
            Debug.Assert(!String.IsNullOrEmpty(complexMemberName), "invalid complexMemberName");

            EntityChangeTracker.EntityComplexMemberChanged(entityMemberName, complexObject, complexMemberName);
        }
Exemple #5
0
        /// <summary>
        /// Fills the data.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="entityFromDto">if private set to <c>true</c> [entity from dto].</param>
        private static void FillData(IDTO dto, ComplexObject entity, bool entityFromDto)
        {
            var dtoType = dto.GetType();
            var entityType = entity.GetType();
            MappingType mappingType;

            if (!VerifyForEntityType(entityType, dtoType, out mappingType))
            {
                throw new EntityConversionException(string.Format(Thread.CurrentThread.CurrentCulture, "Entity type '{0}' must match with type specified in EntityMappingAttribute on type '{1}' !", entityType.ToString(), dtoType.ToString()));
            }

            var properties = dtoType.GetProperties();

            foreach (PropertyInfo property in properties)
            {
                bool skipThisProperty = false;
                object[] customAttributes = property.GetCustomAttributes(typeof(EntityPropertyMappingAttribute), false);
                if (mappingType == MappingType.TotalExplicit && customAttributes.Length == 0)
                {
                    continue;
                }

                foreach (object customAttribute in customAttributes)
                {
                    EntityPropertyMappingAttribute entityPropertyMappingAttribute = (EntityPropertyMappingAttribute)customAttribute;
                    if (entityPropertyMappingAttribute.MappingDirection == MappingDirectionType.None)
                    {
                        skipThisProperty = true;
                        break;
                    }
                }

                if (skipThisProperty)
                {
                    continue;
                }

                var entityPropertyName = GetEntityPropertyName(property, mappingType, entityFromDto);
                if (!string.IsNullOrEmpty(entityPropertyName))
                {
                    var entityProperty = entityType.GetProperty(entityPropertyName);

                    if (entityProperty == null)
                    {
                        throw new EntityConversionException(entityPropertyName, entity);
                    }

                    var sourceProperty = entityFromDto ? property : entityProperty;
                    var destinationProperty = entityFromDto ? entityProperty : property;
                    var sourceObject = entityFromDto ? (dto as object) : (entity as object);
                    var destinationObject = entityFromDto ? (entity as object) : (dto as object);
                    var sourceValue = sourceProperty.GetValue(sourceObject, null);

                    if (destinationProperty.CanWrite)
                    {
                        if (sourceProperty.PropertyType.IsEnum && destinationProperty.PropertyType == typeof(byte))
                        {
                            sourceValue = (byte)(int)sourceValue;
                        }

                        destinationProperty.SetValue(destinationObject, sourceValue, null);
                    }
                }
            }
        }