本文整理汇总了C#中ArrayBuilder.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayBuilder.Sort方法的具体用法?C# ArrayBuilder.Sort怎么用?C# ArrayBuilder.Sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayBuilder
的用法示例。
在下文中一共展示了ArrayBuilder.Sort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillEnumFields
private static void FillEnumFields(ArrayBuilder<EnumField> fields, Type lmrType)
{
var fieldInfos = lmrType.GetFields();
var enumTypeCode = Type.GetTypeCode(lmrType);
foreach (var info in fieldInfos)
{
if (!info.IsSpecialName) // Skip __value.
{
fields.Add(new EnumField(info.Name, ConvertEnumUnderlyingTypeToUInt64(info.GetRawConstantValue(), enumTypeCode)));
}
}
fields.Sort(EnumField.Comparer);
}
示例2: ObfuscatedNamespaceNames_01
public void ObfuscatedNamespaceNames_01()
{
var result = new ArrayBuilder<IGrouping<string, TypeDefinitionHandle>>();
foreach (var namespaceName in new[] { "A.", "A.a", "A..", "A.-" })
{
result.Add(new Grouping<string, TypeDefinitionHandle>(namespaceName, new[] { new TypeDefinitionHandle() }));
}
result.Sort(new PEModule.TypesByNamespaceSortComparer(StringComparer.Ordinal));
// This is equivalent to the result of PEModule.GroupTypesByNamespaceOrThrow
IEnumerable<IGrouping<string, TypeDefinitionHandle>> typesByNS = result;
// The following code is equivalent to code in PENamespaceSymbol.LoadAllMembers
IEnumerable<IGrouping<string, TypeDefinitionHandle>> nestedTypes = null;
IEnumerable<KeyValuePair<string, IEnumerable<IGrouping<string, TypeDefinitionHandle>>>> nestedNamespaces = null;
MetadataHelpers.GetInfoForImmediateNamespaceMembers(
false,
"A".Length,
typesByNS,
StringComparer.Ordinal,
out nestedTypes, out nestedNamespaces);
// We don't expect duplicate keys in nestedNamespaces at this point.
Assert.False(nestedNamespaces.GroupBy(pair => pair.Key).Where(g => g.Count() > 1).Any());
var array = nestedNamespaces.ToArray();
Assert.Equal(3, array.Length);
Assert.Equal("", array[0].Key);
Assert.Equal(2, array[0].Value.Count());
Assert.Equal("-", array[1].Key);
Assert.Equal(1, array[1].Value.Count());
Assert.Equal("a", array[2].Key);
Assert.Equal(1, array[2].Value.Count());
}
示例3: ObfuscatedNamespaceNames_02
public void ObfuscatedNamespaceNames_02()
{
var result = new ArrayBuilder<IGrouping<string, TypeDefinitionHandle>>();
foreach (var namespaceName in new[] { ".a", ".b" })
{
result.Add(new Grouping<string, TypeDefinitionHandle>(namespaceName, new[] { new TypeDefinitionHandle() }));
}
result.Sort(new PEModule.TypesByNamespaceSortComparer(StringComparer.Ordinal));
// This is equivalent to the result of PEModule.GroupTypesByNamespaceOrThrow
IEnumerable<IGrouping<string, TypeDefinitionHandle>> typesByNS = result;
// The following code is equivalent to code in PENamespaceSymbol.LoadAllMembers
IEnumerable<IGrouping<string, TypeDefinitionHandle>> nestedTypes = null;
IEnumerable<KeyValuePair<string, IEnumerable<IGrouping<string, TypeDefinitionHandle>>>> nestedNamespaces = null;
MetadataHelpers.GetInfoForImmediateNamespaceMembers(
true, // global namespace
0, // global namespace
typesByNS,
StringComparer.Ordinal,
out nestedTypes, out nestedNamespaces);
var nestedNS = nestedNamespaces.Single();
Assert.Equal("", nestedNS.Key);
Assert.Equal(2, nestedNS.Value.Count());
MetadataHelpers.GetInfoForImmediateNamespaceMembers(
false,
nestedNS.Key.Length,
nestedNS.Value,
StringComparer.Ordinal,
out nestedTypes, out nestedNamespaces);
Assert.Equal(2, nestedNamespaces.Count());
Assert.Equal("a", nestedNamespaces.ElementAt(0).Key);
Assert.Equal("b", nestedNamespaces.ElementAt(1).Key);
}
示例4: GetSortedEnumFields
private static void GetSortedEnumFields(
INamedTypeSymbol enumType,
ArrayBuilder<EnumField> enumFields)
{
var underlyingSpecialType = enumType.EnumUnderlyingType.SpecialType;
foreach (var member in enumType.GetMembers())
{
if (member.Kind == SymbolKind.Field)
{
var field = (IFieldSymbol)member;
if (field.HasConstantValue)
{
var enumField = new EnumField(field.Name, EnumUtilities.ConvertEnumUnderlyingTypeToUInt64(field.ConstantValue, underlyingSpecialType), field);
enumFields.Add(enumField);
}
}
}
enumFields.Sort(EnumField.Comparer);
}