public IRelationship CreateRelationship(IEnumerable <Guid> participants, IEnumerable <string> tags) { long hash = BaseRelationship.GenerateHash(participants); if (this.m_Relationships.ContainsKey(hash)) { List <IRelationship> relationships = this.m_Relationships[hash]; int matching = 0; IRelationship returnRelationship = null; foreach (IRelationship relationship in relationships) { int matches = relationship.Tags.Intersect(tags, StringComparer.OrdinalIgnoreCase).Count(); if (matches <= matching) { continue; } matching = matches; returnRelationship = relationship; } if (returnRelationship is null == false) { return(returnRelationship); } } if (this.m_RelationshipTypes.Any(t => tags.Intersect(t.Value.Tags, StringComparer.OrdinalIgnoreCase).Any())) { int matching = 0; IRelationship found = null; foreach (IRelationship relationship in this.m_RelationshipTypes.Values) { int matches = relationship.Tags.Intersect(tags, StringComparer.OrdinalIgnoreCase).Count(); if (matches <= matching) { continue; } matching = matches; found = relationship; } if (found is null) { return(null); } IRelationship newRelationship = found.Create(participants); //newRelationship.ModifyValueOfAllParticipants(0); this.m_Relationships.Add(newRelationship.GenerateHashFromInstance(), newRelationship); return(newRelationship); } throw new InvalidOperationException("Relationship type " + tags.Print() + " not found."); }