gpt4 book ai didi

vb.net - c#和VB.NET的代码分析

转载 作者:行者123 更新时间:2023-12-05 00:04:55 26 4
gpt4 key购买 nike

我制作一个工具来在运行时检查编码标准意味着我在运行中给标准者检查我正在为标准创建一个 XML 文件并从该 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
  • 关于vb.net - c#和VB.NET的代码分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5139967/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com