Catrobat.IDE.Core.Utilities.Helpers.ReferenceHelper.GetUserVariableObject C# (CSharp) Method

GetUserVariableObject() private static method

private static GetUserVariableObject ( XmlUserVariableReference xmlUserVariableReference, string reference ) : XmlObjectNode
xmlUserVariableReference Catrobat.IDE.Core.Xml.XmlObjects.Variables.XmlUserVariableReference
reference string
return Catrobat.IDE.Core.Xml.XmlObjects.XmlObjectNode
        private static XmlObjectNode GetUserVariableObject(XmlUserVariableReference xmlUserVariableReference, string reference)
        {
            XElement currentElement = xmlUserVariableReference._xRoot;
            string[] array = reference.Split(new char[] { '/'}, StringSplitOptions.RemoveEmptyEntries);

            var matchQuery = from word in array
                             where word.ToLowerInvariant() == ".."
                             select word;

            int stepsDown = matchQuery.Count();

            for(int i=0; i < stepsDown; i++)
            {
                currentElement = currentElement.Parent;
            }

            for(int i=stepsDown; i<array.Length; i++)
            {
                //TODO: throws exception
                string type = array[i].Split('[')[0];
                int number = GetElementNumber(array[i]);

                currentElement = currentElement.Elements(type).ElementAt(number);
            }

            return new XmlUserVariable(currentElement);
        }