OrderBy.cs 715 B

12345678910111213141516171819202122232425262728
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. using System;
  4. using System.Linq;
  5. using Microsoft.Build.Framework;
  6. using Microsoft.Build.Utilities;
  7. namespace RepoTasks
  8. {
  9. public class OrderBy : Task
  10. {
  11. [Required]
  12. [Output]
  13. public ITaskItem[] Items { get; set; }
  14. public string Key { get; set; }
  15. public override bool Execute()
  16. {
  17. var key = string.IsNullOrEmpty(Key)
  18. ? "Identity"
  19. : Key;
  20. Items = Items.OrderBy(k => k.GetMetadata(key)).ToArray();
  21. return true;
  22. }
  23. }
  24. }