Microsoft.CodeAnalysis.Sarif.Converters.CppCheckError.Parse C# (CSharp) Méthode

Parse() public static méthode

Parses the element on which an XmlReader is positioned as a CppCheck error node.
The xml on which is placed is /// in an incorrect format.
public static Parse ( XmlReader reader, CppCheckStrings strings ) : CppCheckError
reader System.Xml.XmlReader The reader from which a CppCheck error shall be read.
strings CppCheckStrings Strings used to parse the CppCheck log.
Résultat CppCheckError
        public static CppCheckError Parse(XmlReader reader, CppCheckStrings strings)
        {
            if (!reader.IsStartElement(strings.Error))
            {
                throw reader.CreateException(ConverterResources.CppCheckElementNotError);
            }

            string id = null;
            string message = null;
            string verboseMessage = null;
            string severity = null;
            while (reader.MoveToNextAttribute())
            {
                string attributeName = reader.LocalName;
                if (Ref.Equal(attributeName, strings.Id))
                {
                    id = reader.Value;
                }
                else if (Ref.Equal(attributeName, strings.Msg))
                {
                    message = reader.Value;
                }
                else if (Ref.Equal(attributeName, strings.Verbose))
                {
                    verboseMessage = reader.Value;
                }
                else if (Ref.Equal(attributeName, strings.Severity))
                {
                    severity = reader.Value;
                }
            }

            reader.MoveToElement();
            ImmutableArray<CppCheckLocation> locations = ParseLocationsSubtree(reader, strings);

            reader.Read(); // Consumes the end element or self closing element and positions the reader on the next node

            try
            {
                return new CppCheckError(
                    id,
                    message,
                    verboseMessage,
                    severity,
                    locations
                    );
            }
            catch (ArgumentException ex)
            {
                throw reader.CreateException(ex.Message);
            }
        }

Usage Example

        private void ProcessCppCheckLog(XmlReader reader, IResultLogWriter issueWriter)
        {
            reader.ReadStartElement(_strings.Results);

            if (!Ref.Equal(reader.LocalName, _strings.CppCheck))
            {
                throw reader.CreateException(SarifResources.CppCheckCppCheckElementMissing);
            }

            string version = reader.GetAttribute(_strings.Version);

            if (String.IsNullOrWhiteSpace(version))
            {
                throw reader.CreateException(SarifResources.CppCheckCppCheckElementMissing);
            }

            issueWriter.WriteToolAndRunInfo(new ToolInfo
            {
                Name    = "CppCheck",
                Version = version,
            }, null);

            reader.Skip(); // <cppcheck />

            if (!Ref.Equal(reader.LocalName, _strings.Errors))
            {
                throw reader.CreateException(SarifResources.CppCheckErrorsElementMissing);
            }

            if (reader.IsEmptyElement)
            {
                reader.Skip(); // <errors />
            }
            else
            {
                int errorsDepth = reader.Depth;
                reader.Read(); // <errors>
                while (reader.Depth > errorsDepth)
                {
                    var parsedError = CppCheckError.Parse(reader, _strings);
                    issueWriter.WriteResult(parsedError.ToSarifIssue());
                }

                reader.ReadEndElement(); // </errors>
            }

            reader.ReadEndElement(); // </results>
        }
All Usage Examples Of Microsoft.CodeAnalysis.Sarif.Converters.CppCheckError::Parse