Microsoft.CodeAnalysis.Sarif.Converters.FortifyPathElement.Parse C# (CSharp) Method

Parse() public static method

Parses an element as a Fortify PathElement node, consuming the node.
public static Parse ( XmlReader xmlReader, FortifyStrings strings ) : FortifyPathElement
xmlReader System.Xml.XmlReader The from which a node shall be parsed. When /// this function returns, this reader is placed directly after the element on which it is /// currently placed.
strings FortifyStrings Strings used in processing Fortify logs.
return FortifyPathElement
        public static FortifyPathElement Parse(XmlReader xmlReader, FortifyStrings strings)
        {
            //<xs:complexType name="PathElement">
            //    <xs:sequence>
            //        <xs:element name="FileName" type="xs:string" minOccurs="1" maxOccurs="1"/>
            //        <xs:element name="FilePath" type="xs:string" minOccurs="1" maxOccurs="1"/>
            //        <xs:element name="LineStart" type="xs:string" minOccurs="1" maxOccurs="1"/>
            //        <xs:element name="Snippet" type="xs:string" minOccurs="0" maxOccurs="1"/>
            //        <xs:element name="SnippetLine" type="xs:int" minOccurs="0" maxOccurs="1"/>
            //        <xs:element name="TargetFunction" type="xs:string" minOccurs="0" maxOccurs="1"/>
            //    </xs:sequence>
            //</xs:complexType>

            if (xmlReader.NodeType != XmlNodeType.Element || xmlReader.IsEmptyElement)
            {
                throw xmlReader.CreateException(ConverterResources.FortifyNotValidPathElement);
            }

            xmlReader.Read(); // Always true because !IsEmptyElement
            xmlReader.IgnoreElement(strings.FileName, IgnoreOptions.Required);
            string filePath = xmlReader.ReadElementContentAsString(strings.FilePath, String.Empty);
            int lineStart = xmlReader.ReadElementContentAsInt(strings.LineStart, String.Empty);
            xmlReader.IgnoreElement(strings.Snippet, IgnoreOptions.Optional);
            xmlReader.IgnoreElement(strings.SnippetLine, IgnoreOptions.Optional);
            string targetFunction = xmlReader.ReadOptionalElementContentAsString(strings.TargetFunction);
            xmlReader.ReadEndElement();

            try
            {
                return new FortifyPathElement(filePath, lineStart, targetFunction);
            }
            catch (ArgumentException ex)
            {
                throw xmlReader.CreateException(ex.Message);
            }
        }

Usage Example

 private static FortifyPathElement Parse(XmlReader reader)
 {
     return(FortifyPathElement.Parse(reader, new FortifyStrings(reader.NameTable)));
 }
All Usage Examples Of Microsoft.CodeAnalysis.Sarif.Converters.FortifyPathElement::Parse
FortifyPathElement