用于c#和VB.NET的代码分析器

制作一个toool来检查运行时标记的代码意味着我在运行中给出了standered以检查我是否在该 XML文件的整个项目中创建了一个用于standered和cheking的XML文件.
我有其他功能在开始功能之前给出评论.

代码在VB中正常工作以进行评论

While oRead.Peek <> -1
                strLineIn = oRead.ReadLine().Trim
                intLineNo = intLineNo + 1
                Dim arr As String() = SplitWords(strLineIn)
                'To update the Progress Bar 
                setProgressBar(intLineNo, intLinesCount)

                If Not strLineIn.StartsWith("'") Then

                    If (strLineIn.Contains("Sub") Or strLineIn.Contains("Function")) _
                        And Not (strLineIn.Contains("End Sub") Or strLineIn.Contains("End Function")) _
                        And Not (strLineIn.Contains("Exit Sub") Or strLineIn.Contains("Exit Function")) _
                        And Not strLineIn.StartsWith("'") Then
                        Select Case Array.IndexOf(arr, "Sub")
                            Case 0, 1, 2
                                createErrorLog(strLineIn, fi.Name, intLineNo, "No Commnet Line for Sub Procedure", fi, strErroLogFile)
                        End Select
                        Select Case Array.IndexOf(arr, "Function")
                            Case 0, 1, 2
                                createErrorLog(strLineIn, fi.Name, intLineNo, "No Commnet line for Function", fi, strErroLogFile)
                        End Select
                    End If
                Else
                    'createErrorLog(processXMLComment(oRead), fi.Name, intLineNo, "No Commnet Line", fi)
                    strLineIn = processXMLComment(oRead, intLineNo)
                End If
                If Not strLineIn.Trim.StartsWith("'") Then
                    For intVar As Integer = 0 To DataType.Count - 1
                        If strLineIn.Contains(DataType(intVar).InnerText) Then
                            arr = SplitWords(strLineIn)
                            For inti As Integer = 0 To arr.Length - 1
                                If arr(inti) = DataType(intVar).InnerText Then
                                    If (arr(inti - 1) = "As") Then
                                        If strLineIn.LastIndexOf(",") = strLineIn.IndexOf(arr(inti - 2)) - 2 Then
                                            Dim intPosition As Integer = 2
                                            For Each c In strLineIn
                                                If Not arr(inti - intPosition).StartsWith(VarName(intVar).InnerText) Then
                                                    createErrorLog(strLineIn, fi.Name, intLineNo, arr(inti - intPosition), fi, strErroLogFile)
                                                End If
                                                intPosition = intPosition + 1
                                                If arr(inti - intPosition) = "Dim" Or arr(inti - intPosition) = "Private" Then
                                                    Exit For
                                                End If
                                            Next
                                        Else
                                            If Not arr(inti - 2).StartsWith(VarName(intVar).InnerText) Then
                                                If Not (strLineIn.Contains("Function") And _
                                                arr(arr.Length - 3) = arr(inti - 2)) Then
                                                    createErrorLog(strLineIn, fi.Name, intLineNo, arr(inti - 2), fi, strErroLogFile)
                                                End If
                                            End If

                                        End If
                                    End If

                                End If
                            Next
                        End If
                    Next
                End If
            End While
            oRead.Close()
            intLineNo = 0

但是当我在c#.net中实现它不能正常工作时,我很困惑地检查c#函数编码标准.

这是c#.net的代码

While oRead.Peek <> -1
                strLineIn = oRead.ReadLine().Trim
                intLineNo = intLineNo + 1
                setProgressBar(intLineNo, intLinesCount)
                If strLineIn.StartsWith("/*") Then
                    bCommentLine = True
                ElseIf strLineIn.StartsWith("*/") Then
                    bCommentLine = False
                End If
                Dim arr As String() = Splitline(strLineIn)

                ' code adding
                If Not strLineIn.StartsWith("//") Then
                    If Not strLineIn.Trim.EndsWith(";") And _
                        Not strLineIn.Trim.StartsWith("{") And _
                        Not strLineIn.Trim.StartsWith("}") And _
                        Not strLineIn.StartsWith("//") And _
                        Not strLineIn.Trim.ToString = "" And _
                        Not find(strLineIn.Trim) Then
                        createErrorLog(strLineIn, fi.Name, intLineNo, "No Commnet Line", fi, strErroLogFile)
                    End If
                Else
                    'createErrorLog(processXMLComment(oRead), fi.Name, intLineNo, "No Commnet Line", fi)
                    strLineIn = processXMLComment(oRead, intLineNo)
                End If

                If Not (strLineIn.StartsWith("//") Or strLineIn.StartsWith("///")) And bCommentLine = False Then
                    For intVar As Integer = 0 To DataType.Count - 1
                        If strLineIn.Contains(DataType(intVar).InnerText) Then
                            arr = Splitline(strLineIn)
                            For inti As Integer = 0 To arr.Length - 1

                                If arr(inti) = DataType(intVar).InnerText Then

                                    If strLineIn.IndexOf(c) = strLineIn.IndexOf(arr(inti + 1)) + 1 And _
                                    strLineIn.Trim.IndexOf(";") = strLineIn.Length - 1 Then
                                        Dim intPosition As Integer = 1
                                        For Each c In strLineIn
                                            If Not arr(inti + intPosition).StartsWith(VarName(intVar).InnerText) Then
                                                createErrorLog(strLineIn, fi.Name, intLineNo, arr(inti + intPosition), fi, strErroLogFile)
                                            End If
                                            intPosition = intPosition + 1
                                            If arr(inti + intPosition) = "" Then
                                                Exit For
                                            End If
                                        Next
                                    Else

                                        If Not arr(inti + 1).StartsWith(VarName(intVar).InnerText) Then
                                            createErrorLog(strLineIn, fi.Name, intLineNo, arr(inti + 1), fi, strErroLogFile)
                                        End If
                                    End If

                                End If

                            Next
                        End If
                    Next
                End If

            End While
            oRead.Close()
            intLineNo = 0

请帮助我解决这个问题.

使用现有的分析工具而不是自己分析工具不是更好吗?这些工具应该给你一些帮助:

> FxCop
> StyleCop

相关文章
相关标签/搜索