public static DslModeling::ElementLink Connect(DslModeling::ModelElement source, DslModeling::ModelElement target) { if (source == null) { throw new global::System.ArgumentNullException("source"); } if (target == null) { throw new global::System.ArgumentNullException("target"); } if (CanAcceptSourceAndTarget(source, target)) { if (source is global::Company.FamilyTree.Town) { if (target is global::Company.FamilyTree.Person) { global::Company.FamilyTree.Town sourceAccepted = (global::Company.FamilyTree.Town)source; global::Company.FamilyTree.Person targetAccepted = (global::Company.FamilyTree.Person)target; DslModeling::ElementLink result = new global::Company.FamilyTree.Residence(sourceAccepted, targetAccepted); if (DslModeling::DomainClassInfo.HasNameProperty(result)) { DslModeling::DomainClassInfo.SetUniqueName(result); } return(result); } } } global::System.Diagnostics.Debug.Fail("Having agreed that the connection can be accepted we should never fail to make one."); throw new global::System.InvalidOperationException(); }
public static global::Company.FamilyTree.FamilyTreeModel GetParentForTown(global::Company.FamilyTree.Town root) { // Segments 0 and 1 global::Company.FamilyTree.FamilyTreeModel result = root.FamilyTreeModel; if (result == null) { return(null); } return(result); }
public static bool CanAcceptSourceAndTarget(DslModeling::ModelElement candidateSource, DslModeling::ModelElement candidateTarget) { // Accepts null, null; source, null; source, target but NOT null, target if (candidateSource == null) { if (candidateTarget != null) { throw new global::System.ArgumentNullException("candidateSource"); } else // Both null { return(false); } } bool acceptSource = CanAcceptSource(candidateSource); // If the source wasn't accepted then there's no point checking targets. // If there is no target then the source controls the accept. if (!acceptSource || candidateTarget == null) { return(acceptSource); } else // Check combinations { if (candidateSource is global::Company.FamilyTree.Town) { if (candidateTarget is global::Company.FamilyTree.Person) { global::Company.FamilyTree.Town sourceTown = (global::Company.FamilyTree.Town)candidateSource; global::Company.FamilyTree.Person targetPerson = (global::Company.FamilyTree.Person)candidateTarget; if (targetPerson == null || global::Company.FamilyTree.Residence.GetLinkToTown(targetPerson) != null) { return(false); } if (targetPerson == null || sourceTown == null || global::Company.FamilyTree.Residence.GetLinks(sourceTown, targetPerson).Count > 0) { return(false); } return(true); } } } return(false); }