1

メソッドのリストと各メソッドのメンバーのリストを返す CQLinq クエリがあります。クエリ結果をエクスポートすると、要素の数のみが表示されます。Linq を使用することを考えましたAggregate( (a,b) => a + ',' + b)。より良い解決策はありますか?

let type = Application.Types.WithFullName("WPF.ViewModels.CouponViewModel").Single()
let dicoFields  =  type.Fields
   .ToDictionary(f => f, f => f.MethodsUsingMe.Where(m => m.ParentType == f.ParentType))
let dicoMethods = type.Methods
   .ToDictionary(m => m, m => m.MembersUsed.Where(f => f.ParentType == m.ParentType))

// The partition algorithm on both dicos here

//from pair in dicoFields 
//orderby   pair.Value.Count() descending
//select new { pair.Key, pair.Value } 

from pair in dicoMethods 
orderby   pair.Value.Count() descending
select new { pair.Key, pair.Value} 

ここに画像の説明を入力

4

1 に答える 1

1

実際、クエリを次のように書き直すことができます。

let type = Application.Types.WithFullName("WPF.ViewModels.CouponViewModel").Single()
let dicoMembers  =  type.ChildMembers
   .ToDictionary(x => x, x => 
  x.IsField ? x.AsField.MethodsUsingMe.Where(m => m.ParentType == x.ParentType):
              x.AsMethod.MembersUsed.Where(f => f.ParentType == x.ParentType))

from pair in dicoMembers
orderby   pair.Value.Count() descending
select new { 
 pair.Key, 
 str = pair.Value.Any() ?
    pair.Value.Select(x => x.Name).Aggregate( (a,b) => a + " ; " + b) :
    "empty"
} 
  • メソッドとフィールドの両方が考慮されます
  • メソッドで使用されるフィールドとメンバーを使用するメソッドは、文字列に集約されます

次に、結果をエクスポートできます。

NDepend クエリ結果のエクスポート

于 2021-07-15T07:43:05.727 に答える