@@ -31,61 +31,62 @@ namespace SysML2.NET.Extensions
3131 public static class ElementExtensions
3232 {
3333 /// <summary>
34- /// Assigns the containment ownership of a child <see cref="IElement"/> to a parent <see cref="IElement"/> via the bridge <see cref="IRelationship"/>
34+ /// Assigns the containment ownership of a target <see cref="IElement"/> to a source <see cref="IElement"/> via the bridge <see cref="IRelationship"/>
3535 /// </summary>
36- /// <param name="parent ">The container<see cref="IElement"/></param>
36+ /// <param name="source ">The container<see cref="IElement"/></param>
3737 /// <param name="bridgeRelationship">The bridge <see cref="IRelationship"/></param>
38- /// <param name="child ">The contained <see cref="IElement"/></param>
38+ /// <param name="target ">The contained <see cref="IElement"/></param>
3939 /// <exception cref="ArgumentNullException">If one of the parameter is null</exception>
40- /// <exception cref="InvalidOperationException">If the <paramref name="parent"/> equals the <paramref name="child"/>
41- /// or if the <paramref name="bridgeRelationship"/> equals the <paramref name="child"/></exception>
42- public static void AssignOwnership ( this IElement parent , IRelationship bridgeRelationship , IElement child )
40+ /// <exception cref="InvalidOperationException">If the <paramref name="source"/> equals the <paramref name="target"/>
41+ /// or if the <paramref name="bridgeRelationship"/> equals the <paramref name="target"/></exception>
42+ /// <remarks>Note: The source is the container element and the target is the containee</remarks>
43+ public static void AssignOwnership ( this IElement source , IRelationship bridgeRelationship , IElement target )
4344 {
44- if ( parent == null )
45+ if ( source == null )
4546 {
46- throw new ArgumentNullException ( nameof ( parent ) ) ;
47+ throw new ArgumentNullException ( nameof ( source ) ) ;
4748 }
4849
4950 if ( bridgeRelationship == null )
5051 {
5152 throw new ArgumentNullException ( nameof ( bridgeRelationship ) ) ;
5253 }
5354
54- if ( child == null )
55+ if ( target == null )
5556 {
56- throw new ArgumentNullException ( nameof ( child ) ) ;
57+ throw new ArgumentNullException ( nameof ( target ) ) ;
5758 }
5859
59- if ( parent == child )
60+ if ( source == target )
6061 {
6162 throw new InvalidOperationException ( "The parent cannot own itself." ) ;
6263 }
6364
64- if ( bridgeRelationship == child )
65+ if ( bridgeRelationship == target )
6566 {
6667 throw new InvalidOperationException ( "The relationship can not own itself." ) ;
6768 }
6869
6970 // Missing logic: Child can not contain Parent at any containment level
7071
71- if ( bridgeRelationship . OwningRelatedElement != null && bridgeRelationship . OwningRelatedElement != parent )
72+ if ( bridgeRelationship . OwningRelatedElement != null && bridgeRelationship . OwningRelatedElement != source )
7273 {
7374 ( ( IContainedElement ) bridgeRelationship . OwningRelatedElement ) . OwnedRelationship . Remove ( bridgeRelationship ) ;
7475 }
7576
76- ( ( IContainedRelationship ) bridgeRelationship ) . OwningRelatedElement = parent ;
77+ ( ( IContainedRelationship ) bridgeRelationship ) . OwningRelatedElement = source ;
7778
78- if ( ! parent . OwnedRelationship . Contains ( bridgeRelationship ) )
79+ if ( ! source . OwnedRelationship . Contains ( bridgeRelationship ) )
7980 {
80- ( ( IContainedElement ) parent ) . OwnedRelationship . Add ( bridgeRelationship ) ;
81+ ( ( IContainedElement ) source ) . OwnedRelationship . Add ( bridgeRelationship ) ;
8182 }
8283
83- if ( child . OwningRelationship != null && child . OwningRelationship != bridgeRelationship )
84+ if ( target . OwningRelationship != null && target . OwningRelationship != bridgeRelationship )
8485 {
85- ( ( IContainedRelationship ) child . OwningRelationship ) . OwnedRelatedElement . Remove ( child ) ;
86+ ( ( IContainedRelationship ) target . OwningRelationship ) . OwnedRelatedElement . Remove ( target ) ;
8687 }
8788
88- ( ( IContainedRelationship ) bridgeRelationship ) . OwnedRelatedElement . Add ( child ) ;
89+ ( ( IContainedRelationship ) bridgeRelationship ) . OwnedRelatedElement . Add ( target ) ;
8990 }
9091 }
9192}
0 commit comments