private static bool TryGetStateInCategory(string memberName, IElement entitySave, out string foundType) { foundType = ""; if (entitySave.StateCategoryList.Count != 0 && memberName.StartsWith("Current") && memberName.EndsWith("State")) { string possibleCategory = StateSaveExtensionMethods.GetStateTypeFromCurrentVariableName(memberName); // See if there is a matching category StateSaveCategory category = entitySave.GetStateCategory(possibleCategory); if (category != null) { foundType = category.Name; return(true); } } return(false); }
public static void FillPossibleStatesFor(List <string> listToFill, string selectedItemName, NamedObjectSave currentNamedObject) { IElement element = currentNamedObject.GetReferencedElement(); while (element != null) { IEnumerable <StateSave> stateList = element.States; // Let's see if this element has a variable by this name CustomVariable foundVariable = element.GetCustomVariableRecursively(selectedItemName); if (foundVariable != null) { FillPossibleStatesFor(listToFill, element, foundVariable); break; } else { listToFill.Add("<NONE>"); bool useDefaultStateList = selectedItemName == "CurrentVariableState" || (foundVariable == null && selectedItemName == "CurrentState"); if (useDefaultStateList) { foreach (StateSave state in element.States) { listToFill.Add(state.Name); } foreach (StateSaveCategory ssc in element.StateCategoryList) { if (ssc.SharesVariablesWithOtherCategories) { foreach (StateSave state in ssc.States) { listToFill.Add(state.Name); } } } } else { if (!useDefaultStateList) { string stateCategory = ""; if (foundVariable != null) { stateCategory = foundVariable.Type; } else { stateCategory = StateSaveExtensionMethods.GetStateTypeFromCurrentVariableName(selectedItemName); } StateSaveCategory category = element.GetStateCategory(stateCategory); if (category != null) { stateList = category.States; } } foreach (StateSave state in stateList) { listToFill.Add(state.Name); } } element = ObjectFinder.Self.GetIElement(element.BaseElement); } } }