/// <summary> /// Returns the InstanceSave that uses this representation or the /// instance that has a a contained instance that uses this representation. /// </summary> /// <param name="representation">The representation in question.</param> /// <returns>The InstanceSave or null if one isn't found.</returns> public InstanceSave GetInstance(IRenderableIpso representation, InstanceFetchType fetchType, List <ElementWithState> elementStack) { ElementSave selectedElement = SelectedState.Self.SelectedElement; string prefix = selectedElement.Name + "."; if (selectedElement is ScreenSave) { prefix = ""; } return(GetInstance(representation, selectedElement, prefix, fetchType, elementStack)); }
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); }
public InstanceSave GetInstance(IPositionedSizedObject 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(); 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; } } } return(toReturn); }