ABB.Swum.ContextBuilder.FindEnclosingClassElement C# (CSharp) Method

FindEnclosingClassElement() private static method

Finds the nearest class or struct element that encloses the given element.
private static FindEnclosingClassElement ( System.Xml.Linq.XElement startElement ) : System.Xml.Linq.XElement
startElement System.Xml.Linq.XElement The element from which to start looking for the enclosing class or struct.
return System.Xml.Linq.XElement
        private static XElement FindEnclosingClassElement(XElement startElement)
        {
            if (startElement == null) { return null; }

            var ancestors = from a in startElement.Ancestors()
                            where a.Name == SRC.Class || a.Name == SRC.Struct
                            select a;
            if (ancestors.Count() > 0)
            {
                return ancestors.First();
            }
            else
            {
                return null;
            }
        }