public static Stack Index(this Stack Stack) { bool FoundInstance = false; string LastStackObject = ""; string LastRelatedStackObject = ""; string Marker = ""; int InstanceStart = 0; int InstanceStop = 0; int Instance = 0; int Step = 0; StackObjectIndex StackObjectIndex = new StackObjectIndex(); StackObjectCommandIndex CurrentIndex; try { foreach (StackObject StackObject in Stack.StackObjects) { Stack.StackIndex++; CurrentIndex = GetStackObjectIndex(Stack); if ((Stack.StackObjectCommandIndexes != null)) { LastStackObject = Stack.StackObjectIndexes.StackObjectCommandTypes[Stack.StackIndex].ToString(); LastRelatedStackObject = Stack.StackObjectIndexes.RelatedStackObjectCommandTypes[Stack.StackIndex].ToString(); switch (Stack.StackObjectCommandIndexes[Stack.StackIndex].StackIndexType) { case StackIndexType.Point: Marker = Stack.StackObjects[Stack.StackIndex].Children[0].StackObjectValue; StackObjectIndex.AddNewIndex(Marker, InstanceStart, InstanceStop, Instance, Step, CurrentIndex.StackCommandType, CurrentIndex.RelatedStackCommandType, "", ""); Marker = ""; break; case StackIndexType.StartPoint: Instance++; InstanceStart++; Step++; StackObjectIndex.AddNewIndex(Marker, InstanceStart, InstanceStop, Instance, Step, CurrentIndex.StackCommandType, CurrentIndex.RelatedStackCommandType, "", ""); InstanceStart -= 1; break; case StackIndexType.EndPoint: while (FoundInstance == false) { if (StackObjectIndex.HasStopInstance(Instance)) { Instance -= 1; if (Instance == 0) { //THROW ERROR - MISSING START POINT throw new ExceptionManager.NewException("StackIndexingException: The StackObject: '" + CurrentIndex.StackCommandType.ToString() + "' is missing the starting StackObject: '" + CurrentIndex.RelatedStackCommandType.ToString() + "' at StackIndex: '" + Stack.StackIndex.ToString() + "'."); } } else { InstanceStop = Instance; if (!StackObjectIndex.HasMatchingStartInstance(CurrentIndex.StackCommandType, InstanceStop)) { //THROW ERROR - MISSING START POINT throw new ExceptionManager.NewException("StackIndexingException: The StackObject: '" + CurrentIndex.StackCommandType.ToString() + "' is missing the starting StackObject: '" + CurrentIndex.RelatedStackCommandType.ToString() + "' at StackIndex: '" + Stack.StackIndex.ToString() + "'."); } FoundInstance = true; Instance -= 1; StackObjectIndex.AddNewIndex(Marker, InstanceStart, InstanceStop, Instance, Step, CurrentIndex.StackCommandType, CurrentIndex.RelatedStackCommandType, "", ""); InstanceStop = Instance; } } FoundInstance = false; break; case StackIndexType.FunctionStartPoint: //Index A UserFunction if (StackObjectIndex.HasStopInstance(Instance)) { Instance -= 1; if (Instance == 0) { //THROW ERROR - MISSING START POINT throw new ExceptionManager.NewException("StackIndexingException: The StackObject: '" + CurrentIndex.StackCommandType.ToString() + "' is missing the starting StackObject: '" + CurrentIndex.RelatedStackCommandType.ToString() + "' at StackIndex: '" + Stack.StackIndex.ToString() + "'."); } } else { InstanceStop = Instance; if (!StackObjectIndex.HasMatchingStartInstance(CurrentIndex.StackCommandType, InstanceStop)) { //THROW ERROR - MISSING START POINT throw new ExceptionManager.NewException("StackIndexingException: The StackObject: '" + CurrentIndex.StackCommandType.ToString() + "' is missing the starting StackObject: '" + CurrentIndex.RelatedStackCommandType.ToString() + "' at StackIndex: '" + Stack.StackIndex.ToString() + "'."); } FoundInstance = true; Instance -= 1; StackObjectIndex.AddNewIndex(Marker, InstanceStart, InstanceStop, Instance, Step, CurrentIndex.StackCommandType, CurrentIndex.RelatedStackCommandType, "", Stack.StackObjects[Stack.StackIndex].StackObjectValue); } break; case StackIndexType.FunctionEndPoint: //Index A UserFunctionEndPoint Instance++; InstanceStart++; Step++; StackObjectIndex.AddNewIndex(Marker, InstanceStart, InstanceStop, Instance, Step, CurrentIndex.StackCommandType, CurrentIndex.RelatedStackCommandType, Stack.StackObjects[Stack.StackIndex].StackObjectValue, ""); break; } } else { StackObjectIndex.AddNewIndex(Marker, InstanceStart, InstanceStop, Instance, Step, StackObjectCommandType.None, StackObjectCommandType.None, "", ""); } } if (Instance > 0) { //THROW ERROR - MISSING END POINT(s) throw new ExceptionManager.NewException("StackIndexingException: The StackObject: '" + LastStackObject + "' is missing the ending StackObject: '" + LastRelatedStackObject + "' at StackIndex: '" + Stack.StackIndex.ToString() + "'."); } } catch (Exception) { throw; } return Stack; }