Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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);
            }
        }