private UmlRelation GetRelation <T>(UmlClass startClass, UmlClass endClass, string name = null, string startMultiplicity = "1", string endMultiplicity = "1") { var rel = Relations.FirstOrDefault( r => r is T && r.StartClass == startClass && r.EndClass == endClass && (name == null || r.Label.ToLower() == name.ToLower()) ); if (rel != null) { if (rel.StartMultiplicity != startMultiplicity || rel.EndMultiplicity != endMultiplicity) { throw new ArgumentException("Relation already exists but StartMultiplicity or EndMultiplicity is different"); } return(rel); } return(null); }
public virtual Tuple <Relation, Relation> GetNextRelationPair() { var first = Relations.FirstOrDefault(relation => relation.IsChosen == ChosenState.HadNotChosen); if (first == null) { return(null); } var second = Relations.SingleOrDefault( relation => relation.Source.Equals(first.Destination) && relation.Destination.Equals(first.Source)); if (second == null) { throw new Exception( $"{this} has not relation {first.Destination} - {first.Source} " + $"although has {first.Source} - {first.Destination}"); } return(new Tuple <Relation, Relation>(first, second)); }