/// <summary> /// Occurs when the Assocations collection has changed. /// </summary> /// <param name="sender">Object that has raised the event</param> /// <param name="e">Information about the change</param> protected void OnAssociationsChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { foreach (Association assoc in e.NewItems) { _ImplAssociation implAssoc = (assoc as _ImplAssociation); if (implAssoc == null) { associations.Remove(assoc); throw new ArgumentException("An Association element created outside the model library " + "was added to the Associations colletion!"); } adaptedElement.OwnedMember.Add(implAssoc.AdaptedAssociation); } } else if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (Association assoc in e.OldItems) { adaptedElement.OwnedMember.Remove((assoc as _ImplAssociation).AdaptedAssociation); } } }
/// <summary> /// Creates a new association bound to the given class and inserts /// a reference to the association into the class associations collection. /// </summary> /// <param name="parentAssociation">Reference to the association that owns this end</param> /// <param name="end">Reference to the class that should be bound to this end</param> /// <param name="_schema"> /// Reference to the Schema instance that is the top /// of this model hierarchy. /// </param> public _AssociationEnd(_ImplAssociation parentAssociation, Class end, Schema _schema) : base(_schema) { adaptedElement = NUml.Uml2.Create.Property(); association = parentAssociation; adaptedElement.Association = parentAssociation.AdaptedAssociation; try { parentClass = end; if (!end.Assocations.Contains(parentAssociation)) { end.Assocations.Add(parentAssociation); } adaptedElement.Type = (end as _ImplClass).AdaptedClass; } catch (NullReferenceException) { throw new ArgumentException("Reference to a class element created outside the model" + " library has been passed to the model!"); } }