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


C# RawList.Sort方法代码示例

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


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

示例1: Sort

		[Test] public void Sort()
		{
			int[] testArray = Enumerable.Range(0, 10).ToArray();
			RawList<int> intList = new RawList<int>();

			// Sorting an empty array is a no-op, but entirely valid. No exceptions expected.
			intList.Sort();

			// Insert the reversed data
			intList.AddRange(testArray.Reverse().ToArray());
			CollectionAssert.AreEqual(testArray.Reverse(), intList);

			// Sort it and check if its equal to the original data
			intList.Sort();
			CollectionAssert.AreEqual(testArray, intList);
		}
开发者ID:Scottyaim,项目名称:duality,代码行数:16,代码来源:RawListTest.cs

示例2: SelectImporter

        protected RawList<ImportInputAssignment> SelectImporter(AssetImportEnvironment env)
        {
            if (!env.IsPrepareStep) throw new ArgumentException(
                "The specified import environment must be configured as a preparation environment.",
                "env");

            // Find an importer to handle some or all of the unhandled input files
            RawList<ImportInputAssignment> candidateMapping = new RawList<ImportInputAssignment>();
            foreach (IAssetImporter importer in AssetManager.Importers)
            {
                env.ResetAcquiredData();

                try
                {
                    importer.PrepareImport(env);
                }
                catch (Exception ex)
                {
                    Log.Editor.WriteError("An error occurred in the preparation step of '{1}': {0}",
                        Log.Exception(ex),
                        Log.Type(importer.GetType()));
                    continue;
                }

                if (env.HandledInput.Any())
                {
                    candidateMapping.Add(new ImportInputAssignment
                    {
                        Importer = importer,
                        HandledInput = env.HandledInput.ToArray(),
                        ExpectedOutput = env.Output.ToArray()
                    });
                }
            }

            // Sort candidate mapping from most files to least files, so we can solve the biggest conflicts first
            candidateMapping.Sort((a, b) => b.HandledInput.Length - a.HandledInput.Length);

            // Determine if multiple importers intend to handle the same files and resolve conflicts
            List<int> conflictingIndices = new List<int>();
            List<string> conflictingFiles = new List<string>();
            for (int mainIndex = 0; mainIndex < candidateMapping.Count; mainIndex++)
            {
                ImportInputAssignment assignment = candidateMapping[mainIndex];

                // Find all conflicts related to this assignment
                conflictingIndices.Clear();
                conflictingFiles.Clear();
                for (int secondIndex = 0; secondIndex < candidateMapping.Count; secondIndex++)
                {
                    if (secondIndex == mainIndex) continue;

                    ImportInputAssignment conflictAssignment = candidateMapping[secondIndex];
                    IEnumerable<string> mainFiles = assignment.HandledInput.Select(item => item.Path);
                    IEnumerable<string> secondFiles = conflictAssignment.HandledInput.Select(item => item.Path);
                    string[] conflicts = mainFiles.Intersect(secondFiles).ToArray();
                    if (conflicts.Length > 0)
                    {
                        if (conflictingIndices.Count == 0) conflictingIndices.Add(mainIndex);
                        conflictingIndices.Add(secondIndex);
                        conflictingFiles.AddRange(conflicts);
                    }
                }

                // Resolve conflicts with this assignment
                if (conflictingIndices.Count > 0)
                {
                    // Determine which importer to prefer for this conflict
                    ImportInputAssignment[] conflictingAssignments = conflictingIndices.Select(i => candidateMapping[i]).ToArray();
                    int keepIndex = this.ResolveMappingConflict(conflictingAssignments);

                    // If we somehow decided that none of the options is viable, abort the operation
                    if (keepIndex == -1)
                    {
                        candidateMapping.Clear();
                        return candidateMapping;
                    }

                    // Sort indices to remove in declining order and remove their mappings
                    conflictingIndices.Remove(keepIndex);
                    conflictingIndices.Sort((a, b) => b - a);
                    foreach (int index in conflictingIndices)
                    {
                        candidateMapping.RemoveAt(index);
                    }

                    // Start over with the conflict search
                    mainIndex = -1;
                    continue;
                }
            }

            return candidateMapping;
        }
开发者ID:SirePi,项目名称:duality,代码行数:94,代码来源:AssetImportOperation.cs

示例3: Sort

        public void Sort()
        {
            int[] testArray = Enumerable.Range(0, 10).ToArray();
            RawList<int> intList = new RawList<int>();

            intList.AddRange(testArray.Reverse().ToArray());
            CollectionAssert.AreEqual(testArray.Reverse(), intList);

            intList.Sort();
            CollectionAssert.AreEqual(testArray, intList);
        }
开发者ID:ninja2003,项目名称:duality,代码行数:11,代码来源:RawListTest.cs


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