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


C# ArrayBuilder.Sort方法代码示例

本文整理汇总了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);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:15,代码来源:Formatter.Values.cs

示例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());
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:38,代码来源:MetadataHelpersTests.cs

示例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);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:42,代码来源:MetadataHelpersTests.cs

示例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);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:20,代码来源:AbstractSymbolDisplayVisitor.cs


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