/// <summary> /// Creates the deep copy of the <see cref="Poco"/> to write /// </summary> /// <param name="poco">The <see cref="Poco"/> to copy</param> /// <param name="targetIteration">The clone of the target <see cref="Iteration"/></param> private void CreatePocoCopy(Poco poco, Iteration targetIteration) { foreach (var containerList in poco.ContainerLists) { var updatedContainerList = new List <Poco>(); foreach (Poco containedPoco in containerList) { if (!this.copyableIds.Contains(containedPoco.Iid)) { continue; } var clone = containedPoco.Clone(false); clone.Iid = Guid.NewGuid(); switch (clone.ClassKind) { case ClassKind.ElementUsage: this.CreatePocoCopy((ElementUsage)clone, targetIteration); break; default: this.CreatePocoCopy(clone, targetIteration); break; } this.copyThingMap.Add(containedPoco, clone); updatedContainerList.Add(clone); } // clear the list var containerListType = containerList.GetType(); var genericType = containerListType.GetGenericArguments().Single(); var clearMethod = containerListType.GetMethod("Clear"); clearMethod.Invoke(containerList, null); if (!updatedContainerList.Any()) { continue; } // Add items var castContainerList = CastMethod.MakeGenericMethod(genericType) .Invoke(null, new object[] { updatedContainerList }); var addRangeMethod = containerListType.GetMethod("AddRange"); addRangeMethod.Invoke(containerList, new[] { castContainerList }); } }
/// <summary> /// Get the <see cref="PropertyInfo"/> of a <see cref="CDP4Common.CommonData.Thing"/> that are of kind <see cref="AggregationKind.Composite"/> /// </summary> /// <param name="thing"> /// The instance of <see cref="CDP4Common.CommonData.Thing"/> that is being queried /// </param> /// <returns> /// an instance <see cref="IEnumerable{PropertyInfo}"/> /// </returns> private IEnumerable <PropertyInfo> GetPropertyInfos(CDP4Common.CommonData.Thing thing) { IEnumerable <PropertyInfo> containerPropertiesInfo; var exists = this.typeCompositePropertyInfoCache.TryGetValue(thing.GetType(), out containerPropertiesInfo); if (!exists) { containerPropertiesInfo = thing.GetType().GetProperties() .Where(p => Attribute.IsDefined(p, typeof(UmlInformationAttribute)) && ((UmlInformationAttribute)Attribute.GetCustomAttribute(p, typeof(UmlInformationAttribute))).Aggregation == AggregationKind.Composite); this.typeCompositePropertyInfoCache.Add(thing.GetType(), containerPropertiesInfo); } return(containerPropertiesInfo); }