本文整理汇总了C#中System.CodeDom.CodeNamespace.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# CodeNamespace.OrderBy方法的具体用法?C# CodeNamespace.OrderBy怎么用?C# CodeNamespace.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.CodeDom.CodeNamespace
的用法示例。
在下文中一共展示了CodeNamespace.OrderBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SortOptionSets
private static void SortOptionSets(CodeCompileUnit codeUnit)
{
// Attempt to order by name by copying to temp collection, removing all from real collection, then adding back ordered by the name
var temp = new CodeNamespace[codeUnit.Namespaces.Count];
codeUnit.Namespaces.CopyTo(temp, 0);
for (int i = 0; i < codeUnit.Namespaces.Count; i++)
{
codeUnit.Namespaces.RemoveAt(i);
}
codeUnit.Namespaces.AddRange(temp.OrderBy(n => n.Name).ToArray());
for (int i = codeUnit.Namespaces.Count - 1; i >= 0; i--)
{
var nameSpace = codeUnit.Namespaces[i];
// Attempt to order by name by copying to temp collection, removing all from real collection, then adding back ordered by the name
var tmpType = new CodeTypeDeclaration[nameSpace.Types.Count];
nameSpace.Types.CopyTo(tmpType, 0);
for (int j = nameSpace.Types.Count - 1; j >= 0; j--)
{
var type = nameSpace.Types[j];
nameSpace.Types.RemoveAt(j);
var tmpMember = new CodeTypeMember[type.Members.Count];
type.Members.CopyTo(tmpMember, 0);
for (int k = type.Members.Count - 1; k >= 0; k--)
{
type.Members.RemoveAt(k);
}
type.Members.AddRange(tmpMember.OrderBy(m => m.Name).ToArray());
}
nameSpace.Types.AddRange(tmpType.OrderBy(n => n.Name).ToArray());
}
}