public VariableListSave Clone() { VariableListSave toReturn = (VariableListSave)this.MemberwiseClone(); if (ValueAsIList != null) { toReturn.CreateNewList(); foreach (object value in this.ValueAsIList) { toReturn.ValueAsIList.Add(value); } } return(toReturn); }
private static void AssignVariableListSave(this StateSave stateSave, string variableName, object value, InstanceSave instanceSave) { VariableListSave variableListSave = stateSave.GetVariableListSave(variableName); if (variableListSave == null) { if (value is List <string> ) { variableListSave = new VariableListSave <string>(); } variableListSave.Type = "string"; variableListSave.Name = variableName; //if (instanceSave != null) //{ // variableListSave.SourceObject = instanceSave.Name; //} stateSave.VariableLists.Add(variableListSave); } // See comments in AssignVariableSave about why we do this outside of the above if-statement. if (StringFunctions.ContainsNoAlloc(variableName, '.')) { string rootName = variableListSave.Name.Substring(variableListSave.Name.IndexOf('.') + 1); string sourceObjectName = variableListSave.Name.Substring(0, variableListSave.Name.IndexOf('.')); if (instanceSave == null && stateSave.ParentContainer != null) { instanceSave = stateSave.ParentContainer.GetInstance(sourceObjectName); } if (instanceSave != null) { VariableListSave baseVariableListSave = ObjectFinder.Self.GetRootStandardElementSave(instanceSave).DefaultState.GetVariableListSave(rootName); variableListSave.IsFile = baseVariableListSave.IsFile; } variableListSave.Name = variableName; } variableListSave.ValueAsIList = value as IList; }
public static VariableListSave GetVariableListRecursive(this StateSave stateSave, string variableName) { VariableListSave variableListSave = stateSave.GetVariableListSave(variableName); if (variableListSave == null) { // Is this thing the default? ElementSave parent = stateSave.ParentContainer; if (parent != null && stateSave != parent.DefaultState) { throw new NotImplementedException(); } else if (parent != null) { ElementSave baseElement = GetBaseElementFromVariable(variableName, parent); if (baseElement != null) { string nameInBase = variableName; if (StringFunctions.ContainsNoAlloc(variableName, '.')) { // this variable is set on an instance, but we're going into the // base type, so we want to get the raw variable and not the variable // as tied to an instance. nameInBase = variableName.Substring(nameInBase.IndexOf('.') + 1); } return(baseElement.DefaultState.GetVariableListRecursive(nameInBase)); } } return(null); } else { return(variableListSave); } }
/// <summary> /// Attempts to get the value for the argument variableName, or null if not found. /// </summary> /// <param name="variableName">The qualified variable name</param> /// <returns>The value found, or null</returns> public object GetValue(string variableName) { ////////////////////Early Out//////////////// if (ParentContainer == null) { return(null); } //////////////////End Early Out////////////// // Check for reserved stuff if (variableName == "Name") { return(ParentContainer.Name); } else if (variableName == "Base Type") { if (string.IsNullOrEmpty(ParentContainer.BaseType)) { return(null); } else { string baseType = ParentContainer.BaseType; StandardElementTypes returnValue; if (Enum.TryParse <StandardElementTypes>(baseType, out returnValue)) { return(returnValue); } else { return(baseType); } } } if (ToolsUtilities.StringFunctions.ContainsNoAlloc(variableName, '.')) { string instanceName = variableName.Substring(0, variableName.IndexOf('.')); ElementSave elementSave = ParentContainer; InstanceSave instanceSave = null; if (elementSave != null) { instanceSave = elementSave.GetInstance(instanceName); } if (instanceSave != null) { // This is a variable on an instance if (variableName.EndsWith(".Name")) { return(instanceSave.Name); } else if (variableName.EndsWith(".Base Type")) { return(instanceSave.BaseType); } else if (variableName.EndsWith(".Locked")) { return(instanceSave.Locked); } } } VariableSave variableState = GetVariableSave(variableName); // If the user hasn't set this variable on this state, it'll be null. So let's just display null // for now. Eventually we'll display a variable plus some kind of indication that it's an unset variable. if (variableState == null || variableState.SetsValue == false) { VariableListSave variableListSave = GetVariableListSave(variableName); if (variableListSave != null) { return(variableListSave.ValueAsIList); } else { return(null); } } else { return(variableState.Value); } }