Catrobat.IDE.Core.Utilities.Helpers.XPathHelper.GetNameWithIndex C# (CSharp) Method

GetNameWithIndex() private static method

private static GetNameWithIndex ( System.Xml.Linq.XElement element ) : string
element System.Xml.Linq.XElement
return string
        private static string GetNameWithIndex(XElement element)
        {
            // numbering starts with 1
            var index = element.ElementsBeforeSelf(element.Name).Count() + 1;

            // add index only when there are more then 1 elements
            if (index == 1 && !element.ElementsAfterSelf(element.Name).Any()) return element.Name.ToString();

            return element.Name + "[" + index + "]";;
        }
    }