我必須在C#中完成一個項目才能找到每個Java類的方法數量。如何使用c sharp來統計每個java類的方法數量?
我可以使用c#正則表達式找到.java文件中的所有方法,但我想要的是找到每個類的每個類的方法數量,包括內部類。誰能幫我。
string[] lines = File.ReadAllLines(file);
int countLine = 0;
int AllCount = 0;
foreach (string line in lines)
{
countLine = MethodsCount(line);
AllCount = AllCount + countLine;
}
label5.Text = AllCount.ToString();
這裏是計數方法。
private int MethodsCount (string LineOperator)
{
int count = 0;
string[] words = LineOperator.Split('{');
foreach (string word in words)
{
if (Regex.IsMatch(word, @"(static\s|final\s)?(public|private|internal)(\sstatic|\sfinal)?\s(int|boolean|void|double|String|long|String\[\]|String\[\]\[\])?\s([a-z]|[A-Z]+[a-z]+|[a-z]+[A-Z]+)+(\s)*\((\s|\n|\r)*"))
{
count = count + 1;
}
}
return count;
}
如果我們考慮一類
public class vehicle {
public method1() {
---------
}
public method2() {
------
}
public class car extends vehicle {
public method3() {
-------
}
}
}
我想要得到的輸出也有這個數的車輛類的方法,這個數字在汽車類像明智的方法。
包括內部類也我想找到方法的數量 – Randi
哇,我當然不想嘗試通過一個單一的正則表達式,甚至一堆正則表達式。還有一件事可能會出錯:評論,我說。不要介意返回自定義類型的自定義泛型類型的函數。或者其他任何一種完全合理的情況。我認爲你在這裏打開一整桶蠕蟲。 –
要添加信息或澄清您的問題,請編輯問題(請參閱文本下方的「編輯」鏈接),而不是添加評論或答案。 –