public VariableSave GetVariable(string variableName) { switch (ContainerType) { case VariableContainerType.InstanceSave: string instanceName = null; if (ElementStack.Count != 0) { instanceName = ElementStack.Last().InstanceName; } bool onlyIfSetsValue = false; #if DEBUG if (ElementStack.Count != 0) { if (ElementStack.Last().Element == null) { throw new InvalidOperationException("The ElementStack contains an ElementWithState with no Element"); } } #endif var found = mInstanceSave.GetVariableFromThisOrBase(ElementStack, this, variableName, false, onlyIfSetsValue); if (found != null && !string.IsNullOrEmpty(found.ExposedAsName)) { var allExposed = GetExposedVariablesForThisInstance(mInstanceSave, instanceName, ElementStack, variableName); var exposed = allExposed.FirstOrDefault(); if (exposed != null && exposed.Value != null) { found = exposed; } } if (found == null || found.SetsValue == false || found.Value == null) { onlyIfSetsValue = true; found = mInstanceSave.GetVariableFromThisOrBase(ElementStack, this, variableName, false, true); } return(found); case VariableContainerType.StateSave: return(mStateSave.GetVariableRecursive(variableName)); //break; } throw new NotImplementedException(); }
public static object GetValueFromThisOrBase(this InstanceSave instance, List <ElementWithState> elementStack, string variable, bool forceDefault = false) { ElementWithState parentContainer = elementStack.Last(); VariableSave variableSave = instance.GetVariableFromThisOrBase(parentContainer, variable, forceDefault, true); if (variableSave != null) { return(variableSave.Value); } else { VariableListSave variableListSave = parentContainer.Element.DefaultState.GetVariableListSave(instance.Name + "." + variable); if (variableListSave == null) { ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType); if (instanceBase != null) { variableListSave = instanceBase.DefaultState.GetVariableListSave(variable); } } if (variableListSave != null) { return(variableListSave.ValueAsIList); } } // If we get ehre that means there isn't any VariableSave or VariableListSave return(null); }