当前位置: 首页>>代码示例>>C#>>正文


C# IGrouping.ToLookup方法代码示例

本文整理汇总了C#中IGrouping.ToLookup方法的典型用法代码示例。如果您正苦于以下问题:C# IGrouping.ToLookup方法的具体用法?C# IGrouping.ToLookup怎么用?C# IGrouping.ToLookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IGrouping的用法示例。


在下文中一共展示了IGrouping.ToLookup方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SolveNameClash

 /// <summary>
 /// From types with the same Name, create new names progressively
 /// using FullName to disambiguate.
 /// </summary>
 /// <param name="pNameClash">Grouping with clashing name and types
 /// that clash.</param>
 /// <returns></returns>
 private static Dictionary<string, string[]> SolveNameClash(IGrouping<string, Type> pNameClash)
 {
   // Create lookup from FullName to types.
   var lFullNameLookup = pNameClash.ToLookup(lType => lType.FullName);
   // See if there is any duplicated FullName (should never happen).
   List<string> lDuplicatedFullName = lFullNameLookup
                       .Where(lTypes => lTypes.Count() > 1)
                       .Select(lTypes => lTypes.First().FullName)
                       .ToList();
   if (lDuplicatedFullName.Any())
   {
     throw new SystemException("Found classes with same FullName: " + String.Join(", ", lDuplicatedFullName) + ".");
   }
   // Create lists for clashing types, indexes indicating when the
   // FullNames differentiate and lists of 'sections' of FullName
   // reversed.
   List<Type> lClashTypes = lFullNameLookup.Select(lGroup => lGroup.First()).ToList();
   List<int> lDiffIndex = lClashTypes.Select(lType => -1).ToList();
   List<List<string>> lFullNames = lClashTypes.Select(lType => lType.FullName.Split('.').Reverse().ToList()).ToList();
   // Loop through FullName 'sections' until exhaustion of the longest.
   int lMax = lFullNames.Select(lStrings => lStrings.Count()).Max();
   for (int i = 0; i < lMax; i++)
   {
     // Loop through all clashing types.
     for (int j = 0; j < lClashTypes.Count(); j++)
     {
       // Skip types already differentiated.
       if (lDiffIndex[j] != -1) continue;
       string current = lFullNames[j][i];
       // Assume it will differentiate.
       bool lDiffed = true;
       // Loop through all other clashing types to see if
       // this is different from others at this index.
       for (int k = 0; k < lClashTypes.Count(); k++)
       {
         if (k == j) continue;
         if ((lDiffIndex[k] == -1) && (i < lFullNames[k].Count()) && (lFullNames[k][i].Equals(current)))
         {
           lDiffed = false;
           break;
         }
       }
       // Store index of differentiation.
       if (lDiffed) lDiffIndex[j] = i;
     }
   }
   // Create a dictionary with Reversed full names until differentiation.
   Dictionary<string, string[]> lResult = new Dictionary<string, string[]>();
   for (int i = 0; i < lClashTypes.Count(); i++)
   {
     // Unreverse the list using only needed items.
     lFullNames[i] = lFullNames[i].Take(lDiffIndex[i] + 1).ToList();
     lFullNames[i].Reverse();
     lResult[lClashTypes[i].FullName] = lFullNames[i].ToArray();
   }
   return lResult;
 }
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:64,代码来源:SchemaExtractor.cs


注:本文中的IGrouping.ToLookup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。