C# 圈复杂度 还是编程新手,希望你们能帮我解决以下问题。

C# 圈复杂度 还是编程新手,希望你们能帮我解决以下问题。,c#,.net,C#,.net,我有一个程序,包括用于代码视图的文本框和用于查看下面每个问题的结果的标签,以及用于执行函数的按钮。这是项目的简单视图 需要解决的问题: 当我按下按钮读取文本框中的代码并计算代码的复杂度时,我需要函数。 我需要知道代码中有多少属性和对象。 继承类在哪里。 什么是远耦合类 事实上,我已经尝试了很长时间的代码,但我没有得到正确的结果。我完成的: 从.Cs文件中打开示例代码 阅读字符串生成器的代码 用下面的代码获得复杂度,但结果是完全错误的 这是我的代码(我已将其设置为取决于数组中的匹配):

我有一个程序,包括用于代码视图的文本框和用于查看下面每个问题的结果的标签,以及用于执行函数的按钮。这是项目的简单视图

需要解决的问题:
  • 当我按下按钮读取文本框中的代码并计算代码的复杂度时,我需要函数。
  • 我需要知道代码中有多少属性和对象。
  • 继承类在哪里。
  • 什么是远耦合类
    事实上,我已经尝试了很长时间的代码,但我没有得到正确的结果。我完成的:
  • 从.Cs文件中打开示例代码
  • 阅读字符串生成器的代码
  • 用下面的代码获得复杂度,但结果是完全错误的
  • 这是我的代码(我已将其设置为取决于数组中的匹配):

        public int Get_complexity(string SourceCode)
        {
            int result = 0;
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(SourceCode);
    
                char[] delimiterChars = { ' ', '.', '{', '}', '(', ')', ';' };
    
                string SourceCodeText = sb.ToString();
    
                string[] words = SourceCodeText.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
    
                int No_if = FindMatchesInStringArray("if", words);
                int No_elseIf  = FindMatchesInStringArray("elseIf", words);
                int No_while = FindMatchesInStringArray("while", words);
                int No_for = FindMatchesInStringArray("for", words);
                int No_foreach = FindMatchesInStringArray("foreach", words);
                int No_case = FindMatchesInStringArray("case", words);
    
                int No_default = FindMatchesInStringArray("default", words);
                int No_finaly = FindMatchesInStringArray("finaly", words);
                int No_continue = FindMatchesInStringArray("continue", words);
                int No_continues = FindMatchesInStringArray("continues", words);
    
                int No_try = FindMatchesInStringArray("try", words);
                int No_catch = FindMatchesInStringArray("catch", words);
                int No_and_op = FindMatchesInStringArray("&", words);
                int No_or_op = FindMatchesInStringArray("||", words);
                int No_words = words.Length;
    
                result = No_if + No_elseIf + No_while + No_for + No_foreach + No_case + No_default + No_finaly + No_continue + No_continues + No_try + No_catch + No_and_op + No_or_op;
            }
            catch { throw; }
            return result;
        }
    
        public int FindMatchesInStringArray(string markup, string[] strArray)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < strArray.Length; i++)
                {
                    if (markup.ToLower() == strArray[i].ToLower())
                    {
                        result += 1;
                    }
                }
            }
            catch
            {
                throw;
            }
            return result;
        }
    
    public int Get\u复杂性(字符串源代码)
    {
    int结果=0;
    尝试
    {
    StringBuilder sb=新的StringBuilder();
    sb.Append(源代码);
    char[]delimiterChars={','.','{','}','(',')',';'};
    字符串SourceCodeText=sb.ToString();
    string[]words=SourceCodeText.Split(delimiterChars、StringSplitOptions.removeMptyEntries);
    int No_if=FindMatchesInStringArray(“if”,字);
    int No_elseIf=FindMatchesInStringArray(“elseIf”,字);
    int No_while=FindMatchesInStringArray(“while”,单词);
    int No_for=findMatchesInstallingArray(“for”,字);
    int No_foreach=FindMatchesInStringArray(“foreach”,字);
    int No_case=FindMatchesInStringArray(“case”,单词);
    int No_default=FindMatchesInStringArray(“默认”,单词);
    int No_finaly=findMatchesInstallingArray(“finaly”,单词);
    int No_continue=FindMatchesInStringArray(“continue”,字);
    int No_continues=FindMatchesInStringArray(“continues”,字);
    int No_try=findMatchesInstallingArray(“try”,单词);
    int No_catch=FindMatchesInStringArray(“catch”,单词);
    int No_和_op=FindMatchesInStringArray(“&”,字);
    int No_或_op=FindMatchesInStringArray(“| |”,words);
    int No_words=words.Length;
    结果=无条件+无条件+无条件+无条件+无条件+无条件+无默认+无最终+无继续+无继续+无尝试+无捕获+无操作+无操作或无操作;
    }
    接住{throw;}
    返回结果;
    }
    public int FindMatchesInStringArray(字符串标记,字符串[]strArray)
    {
    int结果=0;
    尝试
    {
    for(int i=0;i
    检查独立站点定义,并尝试模拟他们正在做的事情:

    圈复杂度(CC):(为类型、方法定义)(仅适用于C#代码,目前正在开发VB.NET版本)圈复杂度是一种流行的过程软件度量,等于过程中可以做出的决策数量。具体地说,在C#中,方法的CC是1+{在方法体中找到的下列表达式的数目}:

    如果| while | for | foreach | case | default | continue | goto |&&&| | | | catch |三元运算符?:|

    以下表达式不计入CC计算:

    否则| do | switch | try |使用|抛出|最终|返回|对象创建|方法调用|字段访问

    圈复杂度度量是在方法上定义的。为了适应面向对象的世界,这个度量也被定义为类和结构的方法之和。请注意,在计算匿名方法的外部方法的CC时,匿名方法的CC不会被计算在内


    你对哪一部分有意见?还有,你用直接投掷的方式尝试/接球有什么意义?这是所有C代码的默认行为。我不太确定这与圈复杂度有什么关系。在这个过程中,你在哪里感到困惑?这不是寻找圈复杂度。我想你可以在前面的一个问题中找到答案:你现在已经把这个问题变成了4到5个问题,你还没有提供圈复杂度片段。你需要问一个具体的问题,并向我们展示你的具体问题。谢谢,我将阅读本页