ndepend

Cant generate Report using Ndependfor vb.net project


I have a requirement where I want to generate a detailed report using Ndepend for vb.net project wrt below metrics:t 1.Lines of code 2.Forms 3.Tabs 4.Controls 5.Menus.

But I get an error in Ndepend.. saying "only Single Statement queries are supported" Pls help resolve

// <Name> Identify Form and Control Issues </Name>
warnif count > 0;

var formInfos = from f in JustMyCode.Types
                where f.IsClass && f.DeriveFrom("System.Windows.Forms.Form")
                let formName = f.Name
                select new { Form = f, FormName = formName, Methods = f.Methods };

// Check for control declarations
var controlDeclarations = from f in formInfos
                          let controlMethods = f.Methods.Where(m => m.SimpleName == ".ctor" || m.SimpleName == ".cctor")
                          from controlMethod in controlMethods
                          let controlDeclaration = controlMethod.ChildMethods.FirstStmtOrDefault as ICatchClause
                          where controlDeclaration != null
                          let controlInfo = controlDeclaration.Text.Split(' ')
                          where controlInfo.Length > 2 && (controlInfo[0] == "Dim" || controlInfo[0] == "Private")
                          select new { formName = f.FormName, ControlType = controlInfo[1], ControlName = controlInfo[2].TrimEnd(')', ';') };

// Check for tab controls and tabs
var tabControls = from f in formInfos
                  let tabControlMethods = f.Methods.Where(m => m.SimpleName == ".ctor" || m.SimpleName == ".cctor")
                  from tabControlMethod in tabControlMethods
                  from line in tabControlMethod.ChildMethods.ChildMethods.SelectMany(childMethod => childMethod.ChildStatements).OfType<CodeStmt>()
                  where line.Text.Trim().StartsWith("Me.tab")
                  let tabControlInfo = line.Text.Split(' ')
                  where tabControlInfo.Length > 3
                  let tabControlName = tabControlInfo[1].Split('(')[0]
                  let tabName = tabControlInfo[3].TrimEnd(')')
                  select new { formName = f.FormName, TabControlName = tabControlName, TabName = tabName };

// Combine the results
var combinedResults = controlDeclarations.Concat(tabControls);

Solution

  • What about this query that lists all application classes that derive from one or several Winforms classes:

    let winformControls = ThirdParty.Types.Where(t => 
      t.ParentNamespace.Name.StartsWithAny("System.Windows.Form", "System.Drawing") 
      && !t.IsSealed).ToHashSetEx()
    
    
    from t in Application.Types.ThatDeriveFromAny(winformControls) 
    select new { t, derifeFrom = t.BaseClasses.Intersect(winformControls) }