private IReferenceConverter GetReferenceConverter(ReferenceAttribute referenceAttribute, Type sourceEntityType, Type referencedEntityType) { if (ReferenceConversionUtils.IsCollectionPropertyType(sourceEntityType, referenceAttribute)) { return(CreateReferenceConverter(typeof(MultiReferenceAttributeDtoToEntityConverter <,>), sourceEntityType, referencedEntityType)); } return(CreateReferenceConverter(typeof(SingleReferenceAttributeDtoToEntityConverter <,>), sourceEntityType, referencedEntityType)); }
/// <summary> /// Gets the type of the referenced entity. If it is multiple reference the type is got from the generic type of the collection. /// </summary> /// <param name="entity">The source entity</param> /// <param name="referencedAttribute">The referenced attribute of the DTO property</param> /// <returns>The type of the referenced entity</returns> protected Type GetReferencedEntityType(BaseEntity entity, ReferenceAttribute referenceAttribute) { PropertyInfo referencePropertyInfo = entity.GetType().GetProperty(referenceAttribute.RefencedPropertyName); if (ReferenceConversionUtils.IsCollectionPropertyType(entity.GetType(), referenceAttribute)) { return(GetReferencedTargetPropertyGenericType(referencePropertyInfo)); } return(referencePropertyInfo.PropertyType); }
public void Convert(IUnitOfWork unitOfWork, BaseEntity sourceEntity, BaseDto targetDto, PropertyInfo sourcePropertyInfo, ReferenceAttribute referenceAttribute, ReferenceString referenceString) { PropertyInfo referencedEntityPropertyInfo = sourceEntity.GetType().GetProperty(referenceAttribute.RefencedPropertyName); PropertyInfo referencedEntityIdPropertyInfo = ReferenceConversionUtils.GetReferencedPropertyId(sourceEntity, referenceAttribute); //sourceEntity.GetType().GetProperty(ReferenceConversionUtils.GetReferencedId(referenceAttribute)); U referencedEntity = (U)referencedEntityPropertyInfo.GetValue(sourceEntity, null); if (referencedEntity != null) { sourcePropertyInfo.SetValue(targetDto, new ReferenceString(referencedEntity.Id, referencedEntity.ToString())); } }
public void Convert(Connection connection, BaseEntity sourceEntity, BaseDto dto, PropertyInfo sourcePropertyInfo, ReferenceAttribute referenceAttribute, ReferenceString referenceString) { PropertyInfo targetProperty = sourceEntity.GetType().GetProperty(ReferenceConversionUtils.GetReferencedId(referenceAttribute)); if (referenceString == null || string.IsNullOrEmpty(referenceString.GetValue())) { targetProperty.SetValue(sourceEntity, null); } else { targetProperty.SetValue(sourceEntity, referenceString.GetId()); } }