public static string GetAttachmentQualifiedName(this IRenderableIpso ipso, List <ElementWithState> elementStack) { IRenderableIpso parent = ipso.Parent; IRenderableIpso child = ipso; while (parent != null) { if (parent.Tag is ElementSave || parent.Tag == null) { // we found it, so break! break; } else { InstanceSave thisInstance = child.Tag as InstanceSave; if (thisInstance.IsParentASibling(elementStack)) { child = parent; parent = parent.Parent; } else { // we found it, so break; break; } } } if (parent == null) { return(ipso.Name); } else { var parentName = parent.GetAttachmentQualifiedName(elementStack); if (!string.IsNullOrEmpty(parentName)) { return(parentName + "." + ipso.Name); } else { return(ipso.Name); } } }
public InstanceSave GetInstance(IRenderableIpso representation, ElementSave instanceContainer, string prefix, InstanceFetchType fetchType, List <ElementWithState> elementStack) { if (instanceContainer == null) { return(null); } InstanceSave toReturn = null; string qualifiedName = representation.GetAttachmentQualifiedName(elementStack); // strip off the guide name if it starts with a guide qualifiedName = StripGuideOrParentNameIfNecessaryName(qualifiedName, representation); foreach (InstanceSave instanceSave in instanceContainer.Instances) { if (prefix + instanceSave.Name == qualifiedName) { toReturn = instanceSave; break; } } if (toReturn == null) { foreach (InstanceSave instanceSave in instanceContainer.Instances) { ElementSave instanceElement = instanceSave.GetBaseElementSave(); bool alreadyInStack = elementStack.Any(item => item.Element == instanceElement); if (!alreadyInStack) { var elementWithState = new ElementWithState(instanceElement); elementStack.Add(elementWithState); toReturn = GetInstance(representation, instanceElement, prefix + instanceSave.Name + ".", fetchType, elementStack); if (toReturn != null) { if (fetchType == InstanceFetchType.DeepInstance) { // toReturn will be toReturn, no need to do anything } else // fetchType == InstanceInCurrentElement { toReturn = instanceSave; } break; } elementStack.Remove(elementWithState); } } } return(toReturn); }