private static void PopulateProperties(TModelClass Target, TModelClass Source, IMModelClass TargetOwner, ECloneOperationScope CloningScope, bool IsForCloning, MModelPropertyDefinitor[] TargetProperties) { foreach (var PropDef in TargetProperties) { var SourceValue = PropDef.Read(Source); /*T if (//T PropDef.TechName.EndsWith("LinkRoleDef") || * PropDef.TechName == "OwnerRelationshipDef") * Console.WriteLine("debug!"); */ /*T if (PropDef.TechName == "ForegroundBrush") * { * Console.WriteLine("Populating prop ForegroundBrush >>>>>>>>>>>>>>>>>>>>>"); * Console.WriteLine("SourceEnt: {0}, TargetEnt: {1}", Source.GetHashCode(), Target.GetHashCode()); * if (PropDef.IsStoreBoxBased) * { * Console.WriteLine("StoreBox-Source: {0}", PropDef.GetStoreBoxContainer(Source).GetHashCode()); * Console.WriteLine("StoreBox-Target: {0}", PropDef.GetStoreBoxContainer(Target).GetHashCode()); * } * Console.WriteLine("SourceVal: HC={0}", SourceValue.GetHashCode()); * var TarVal = PropDef.Read(Target); * TarVal = TarVal.NullDefault("<NULL>"); * Console.WriteLine("TargetVal: HC={0} (to be overwritten)", TarVal.GetHashCode()); * Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"); * } */ var DoClone = PropDef.IsCloneableFor(CloningScope, Source); if (SourceValue is IMModelClass && DoClone.Item1) { //T PopulationLevel++; SourceValue = ((IMModelClass)SourceValue).CreateCopy(DoClone.Item2, Target); //T PopulationLevel--; } if (PropDef.ReferencesOwner.HasValue && TargetOwner != null) { // NOTE: See ModelFixes.ModelRev7_FixOwnerReferences method, which resulted in this piece of code for reassign Owners. var SourceOwnership = SourceValue as MOwnership; var Owner = (SourceOwnership == null ? SourceValue : SourceOwnership.Owner); if (Owner != null && Owner.GetType() == TargetOwner.GetType()) { if (SourceOwnership != null) { SourceValue = SourceOwnership.CreateClone(TargetOwner); } else { SourceValue = TargetOwner; } } } // Refinements... // Needed because the initial clone only has duplicated the root properties (shallow copy) if (IsForCloning) { var SourceAssignment = SourceValue as MAssignment; if (SourceAssignment != null) { if (SourceAssignment.IsLocal && (SourceAssignment.AssignedValue is IMModelClass) && DoClone.Item1) { SourceAssignment = ((IMModelClass)SourceAssignment.AssignedValue).CreateCopy(DoClone.Item2, Target).Assign(true); } else { SourceAssignment = ((MAssignment)SourceValue).CreateClone(); } SourceValue = SourceAssignment; } if (PropDef.IsStoreBoxBased) { var ClonedStore = PropDef.GetStoreBoxContainer(Target).CreateClone(); PropDef.SetStoreBoxBaseContainer(Target, ClonedStore); } } PropDef.Write(Target, SourceValue); } }