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); }
public List <VariableSave> GetExposedVariablesForThisInstance(DataTypes.InstanceSave instance, string parentInstanceName, List <ElementWithState> elementStack, string requiredName) { List <VariableSave> exposedVariables = new List <VariableSave>(); if (elementStack.Count > 1) { ElementWithState containerOfVariables = elementStack[elementStack.Count - 2]; ElementWithState definerOfVariables = elementStack[elementStack.Count - 1]; foreach (VariableSave variable in definerOfVariables.Element.DefaultState.Variables.Where( item => !string.IsNullOrEmpty(item.ExposedAsName) && item.GetRootName() == requiredName)) { if (variable.SourceObject == instance.Name) { // This variable is exposed, let's see if the container does anything with it VariableSave foundVariable = containerOfVariables.StateSave.GetVariableRecursive( parentInstanceName + "." + variable.ExposedAsName); if (foundVariable != null) { if (!string.IsNullOrEmpty(foundVariable.ExposedAsName)) { // This variable is itself exposed, so we should go up one level to see // what's going on. var instanceInParent = containerOfVariables.Element.GetInstance(parentInstanceName); var parentparentInstanceName = containerOfVariables.InstanceName; List <ElementWithState> stackWithLastRemoved = new List <ElementWithState>(); stackWithLastRemoved.AddRange(elementStack); stackWithLastRemoved.RemoveAt(stackWithLastRemoved.Count - 1); var exposedExposed = GetExposedVariablesForThisInstance(instanceInParent, parentparentInstanceName, stackWithLastRemoved, // This used to be this: //foundVariable.ExposedAsName // But it should be this: variable.ExposedAsName ); if (exposedExposed.Count != 0) { foundVariable = exposedExposed.First(); } } VariableSave variableToAdd = new VariableSave(); variableToAdd.Type = variable.Type; variableToAdd.Value = foundVariable.Value; variableToAdd.SetsValue = foundVariable.SetsValue; variableToAdd.Name = variable.Name.Substring(variable.Name.IndexOf('.') + 1); exposedVariables.Add(variableToAdd); } } } } return(exposedVariables); }
public static VariableSave GetVariableFromThisOrBase(this InstanceSave instance, ElementWithState parent, string variable, bool forceDefault, bool onlyIfSetsValue) { var elementStack = new List <ElementWithState> { parent }; return(GetVariableFromThisOrBase(instance, elementStack, new RecursiveVariableFinder(instance, elementStack), variable, forceDefault, onlyIfSetsValue)); }
public static VariableSave GetVariableFromThisOrBase(this InstanceSave instance, ElementWithState parent, string variable) { var elementStack = new List <ElementWithState> { parent }; return(GetVariableFromThisOrBase(instance, elementStack, new RecursiveVariableFinder(instance, elementStack), variable, false, false)); }
public void PushElement(ElementWithState element) { if (ContainerType != VariableContainerType.StateSave) { throw new Exception(); } mElementStack.Add(element); }
public List <ElementWithState> GetTopLevelElementStack() { List <ElementWithState> toReturn = new List <ElementWithState>(); if (SelectedElement != null) { ElementWithState item = new ElementWithState(SelectedElement); if (this.SelectedStateSave != null) { item.StateName = this.SelectedStateSave.Name; } toReturn.Add(item); } return(toReturn); }