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::CodeGeneration.DSL.Class) { if (target is global::CodeGeneration.DSL.Class) { global::CodeGeneration.DSL.Class sourceAccepted = (global::CodeGeneration.DSL.Class)source; global::CodeGeneration.DSL.Class targetAccepted = (global::CodeGeneration.DSL.Class)target; DslModeling::ElementLink result = new global::CodeGeneration.DSL.ClassReferencesDerivedClasses(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(); }
/// <summary> /// Called by the Merge process to create a relationship between /// this target element and the specified source element. /// Typically, a parent-child relationship is established /// between the target element (the parent) and the source element /// (the child), but any relationship can be established. /// </summary> /// <param name="sourceElement">The element that is to be related to this model element.</param> /// <param name="elementGroup">The group of source ModelElements that have been rehydrated into the target store.</param> /// <remarks> /// This method is overriden to create the relationship between the target element and the specified source element. /// The base method does nothing. /// </remarks> protected override void MergeRelate(DslModeling::ModelElement sourceElement, DslModeling::ElementGroup elementGroup) { // In general, sourceElement is allowed to be null, meaning that the elementGroup must be parsed for special cases. // However this is not supported in generated code. Use double-deriving on this class and then override MergeRelate completely if you // need to support this case. if (sourceElement == null) { throw new global::System.ArgumentNullException("sourceElement"); } global::CodeGeneration.DSL.Class sourceClass1 = sourceElement as global::CodeGeneration.DSL.Class; if (sourceClass1 != null) { // Create link for path MetaModelHasClasses.Classes this.Classes.Add(sourceClass1); return; } // Sdk workaround to runtime bug #879350 (DSL: can't copy and paste a MEL that has a MEX). Avoid MergeRelate on ModelElementExtension // during a "Paste". if (sourceElement is DslModeling::ExtensionElement && sourceElement.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo.ContainsKey("{9DAFD42A-DC0E-4d78-8C3F-8266B2CF8B33}")) { return; } // Fall through to base class if this class hasn't handled the merge. base.MergeRelate(sourceElement, elementGroup); }
internal static global::CodeGeneration.DSL.ClassHasProperties GetLink(global::CodeGeneration.DSL.Class source, global::CodeGeneration.DSL.Property target) { global::System.Collections.Generic.IList <global::CodeGeneration.DSL.ClassHasProperties> links = DslModeling::DomainRoleInfo.GetElementLinks <global::CodeGeneration.DSL.ClassHasProperties>(source, global::CodeGeneration.DSL.ClassHasProperties.ClassDomainRoleId); foreach (global::CodeGeneration.DSL.ClassHasProperties link in links) { if (target.Equals(link.Property)) { return(link); } } return(null); }
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::CodeGeneration.DSL.Class) { if (candidateTarget is global::CodeGeneration.DSL.Class) { global::CodeGeneration.DSL.Class sourceClass = (global::CodeGeneration.DSL.Class)candidateSource; global::CodeGeneration.DSL.Class targetClass = (global::CodeGeneration.DSL.Class)candidateTarget; if (targetClass == null || global::CodeGeneration.DSL.ClassReferencesDerivedClasses.GetLinkToBaseClass(targetClass) != null) { return(false); } if (targetClass == null || sourceClass == null || global::CodeGeneration.DSL.ClassReferencesDerivedClasses.GetLinks(sourceClass, targetClass).Count > 0) { return(false); } return(true); } } } return(false); }
protected override void MergeDisconnect(DslModeling::ModelElement sourceElement) { if (sourceElement == null) { throw new global::System.ArgumentNullException("sourceElement"); } global::CodeGeneration.DSL.Class sourceClass1 = sourceElement as global::CodeGeneration.DSL.Class; if (sourceClass1 != null) { // Delete link for path MetaModelHasClasses.Classes foreach (DslModeling::ElementLink link in global::CodeGeneration.DSL.MetaModelHasClasses.GetLinks((global::CodeGeneration.DSL.MetaModel) this, sourceClass1)) { // Delete the link, but without possible delete propagation to the element since it's moving to a new location. link.Delete(global::CodeGeneration.DSL.MetaModelHasClasses.MetaModelDomainRoleId, global::CodeGeneration.DSL.MetaModelHasClasses.ElementDomainRoleId); } return; } // Fall through to base class if this class hasn't handled the unmerge. base.MergeDisconnect(sourceElement); }
internal static global::CodeGeneration.DSL.ClassReferencesDerivedClasses GetLink(global::CodeGeneration.DSL.Class source, global::CodeGeneration.DSL.Class target) { global::System.Collections.Generic.IList <global::CodeGeneration.DSL.ClassReferencesDerivedClasses> links = DslModeling::DomainRoleInfo.GetElementLinks <global::CodeGeneration.DSL.ClassReferencesDerivedClasses>(source, global::CodeGeneration.DSL.ClassReferencesDerivedClasses.SourceClassDomainRoleId); foreach (global::CodeGeneration.DSL.ClassReferencesDerivedClasses link in links) { if (target.Equals(link.TargetClass)) { return(link); } } return(null); }
internal static global::System.Collections.ObjectModel.ReadOnlyCollection <global::CodeGeneration.DSL.ClassReferencesDerivedClasses> GetLinks(global::CodeGeneration.DSL.Class source, global::CodeGeneration.DSL.Class target) { global::System.Collections.Generic.List <global::CodeGeneration.DSL.ClassReferencesDerivedClasses> outLinks = new global::System.Collections.Generic.List <global::CodeGeneration.DSL.ClassReferencesDerivedClasses>(); global::System.Collections.Generic.IList <global::CodeGeneration.DSL.ClassReferencesDerivedClasses> links = DslModeling::DomainRoleInfo.GetElementLinks <global::CodeGeneration.DSL.ClassReferencesDerivedClasses>(source, global::CodeGeneration.DSL.ClassReferencesDerivedClasses.SourceClassDomainRoleId); foreach (global::CodeGeneration.DSL.ClassReferencesDerivedClasses link in links) { if (target.Equals(link.TargetClass)) { outLinks.Add(link); } } return(outLinks.AsReadOnly()); }
internal static global::CodeGeneration.DSL.ClassReferencesDerivedClasses GetLinkToBaseClass(global::CodeGeneration.DSL.Class targetClassInstance) { global::System.Collections.Generic.IList <global::CodeGeneration.DSL.ClassReferencesDerivedClasses> links = DslModeling::DomainRoleInfo.GetElementLinks <global::CodeGeneration.DSL.ClassReferencesDerivedClasses>(targetClassInstance, global::CodeGeneration.DSL.ClassReferencesDerivedClasses.TargetClassDomainRoleId); global::System.Diagnostics.Debug.Assert(links.Count <= 1, "Multiplicity of TargetClass not obeyed."); if (links.Count == 0) { return(null); } else { return(links[0]); } }
internal static global::System.Collections.ObjectModel.ReadOnlyCollection <global::CodeGeneration.DSL.ClassReferencesDerivedClasses> GetLinksToDerivedClasses(global::CodeGeneration.DSL.Class sourceClassInstance) { return(DslModeling::DomainRoleInfo.GetElementLinks <global::CodeGeneration.DSL.ClassReferencesDerivedClasses>(sourceClassInstance, global::CodeGeneration.DSL.ClassReferencesDerivedClasses.SourceClassDomainRoleId)); }
internal static global::System.Collections.ObjectModel.ReadOnlyCollection <global::CodeGeneration.DSL.ClassHasProperties> GetLinksToProperties(global::CodeGeneration.DSL.Class classInstance) { return(DslModeling::DomainRoleInfo.GetElementLinks <global::CodeGeneration.DSL.ClassHasProperties>(classInstance, global::CodeGeneration.DSL.ClassHasProperties.ClassDomainRoleId)); }
internal static global::CodeGeneration.DSL.MetaModelHasClasses GetLinkToMetaModel(global::CodeGeneration.DSL.Class elementInstance) { global::System.Collections.Generic.IList <global::CodeGeneration.DSL.MetaModelHasClasses> links = DslModeling::DomainRoleInfo.GetElementLinks <global::CodeGeneration.DSL.MetaModelHasClasses>(elementInstance, global::CodeGeneration.DSL.MetaModelHasClasses.ElementDomainRoleId); global::System.Diagnostics.Debug.Assert(links.Count <= 1, "Multiplicity of Element not obeyed."); if (links.Count == 0) { return(null); } else { return(links[0]); } }