PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Atlassian.Jira/IssueLabelCollection.cs

https://bitbucket.org/farmas/atlassian.net-sdk
C# | 64 lines | 45 code | 8 blank | 11 comment | 9 complexity | d700c99e0a9447dcb85cadf0f3b40643 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using System.Collections.Generic;
  2. using System.Diagnostics.CodeAnalysis;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using Atlassian.Jira.Remote;
  7. namespace Atlassian.Jira
  8. {
  9. /// <summary>
  10. /// Collection of labels for an issue.
  11. /// </summary>
  12. [SuppressMessage("N/A", "CS0660", Justification = "Operator overloads are used for LINQ to JQL provider.")]
  13. [SuppressMessage("N/A", "CS0661", Justification = "Operator overloads are used for LINQ to JQL provider.")]
  14. public class IssueLabelCollection : List<string>, IRemoteIssueFieldProvider
  15. {
  16. private readonly List<string> _originalLabels;
  17. /// <summary>
  18. /// Creates a new instance of IssueLabelCollection.
  19. /// </summary>
  20. /// <param name="labels">Labels to seed into this collection</param>
  21. public IssueLabelCollection(IList<string> labels)
  22. : base(labels)
  23. {
  24. _originalLabels = new List<string>(labels);
  25. }
  26. /// <summary>
  27. /// Adds labels to this collection.
  28. /// </summary>
  29. /// <param name="labels">The list of labels to add.</param>
  30. public void Add(params string[] labels)
  31. {
  32. this.AddRange(labels);
  33. }
  34. public static bool operator ==(IssueLabelCollection list, string value)
  35. {
  36. return (object)list == null ? value == null : list.Any(v => v == value);
  37. }
  38. public static bool operator !=(IssueLabelCollection list, string value)
  39. {
  40. return (object)list == null ? value == null : !list.Any(v => v == value);
  41. }
  42. Task<RemoteFieldValue[]> IRemoteIssueFieldProvider.GetRemoteFieldValuesAsync(CancellationToken token)
  43. {
  44. var fieldValues = new List<RemoteFieldValue>();
  45. if (_originalLabels.Count() != this.Count() || this.Except(_originalLabels).Any())
  46. {
  47. fieldValues.Add(new RemoteFieldValue()
  48. {
  49. id = "labels",
  50. values = this.ToArray()
  51. });
  52. }
  53. return Task.FromResult(fieldValues.ToArray());
  54. }
  55. }
  56. }