Skip to content

Commit

Permalink
Initialise collection when accessed
Browse files Browse the repository at this point in the history
  • Loading branch information
thomhurst committed Jan 25, 2025
1 parent 7fa5b0f commit fc283af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 59 deletions.
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Label="Strong name signing">
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)\key.snk</AssemblyOriginatorKeyFile>
Expand Down
70 changes: 11 additions & 59 deletions Octokit/Models/Request/IssueUpdate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using Octokit.Internal;
Expand All @@ -12,6 +11,9 @@ namespace Octokit
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class IssueUpdate
{
private ICollection<string> _labels;
private ICollection<string> _assignees;

/// <summary>
/// Title of the issue (required)
/// </summary>
Expand All @@ -28,7 +30,7 @@ public class IssueUpdate
/// <remarks>
/// Only users with push access can set the multiple assignees for new issues. The assignees are silently dropped otherwise.
/// </remarks>
public ICollection<string> Assignees { get; private set; }
public ICollection<string> Assignees => _assignees ??= [];

/// <summary>
/// Milestone to associate this issue with.
Expand All @@ -46,7 +48,7 @@ public class IssueUpdate
/// <remarks>
/// Only users with push access can set labels for new issues. Labels are silently dropped otherwise.
/// </remarks>
public ICollection<string> Labels { get; private set; }
public ICollection<string> Labels => _labels ??= [];

/// <summary>
/// Whether the issue is open or closed.
Expand All @@ -58,26 +60,14 @@ public class IssueUpdate
/// </summary>
public ItemStateReason? StateReason { get; set; }

internal string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, "Title: {0}", Title);
}
}
internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Title: {0}", Title);

/// <summary>
/// Adds the specified assignees to the issue.
/// </summary>
/// <param name="name">The login of the assignee.</param>
public void AddAssignee(string name)
{
// lazily create the assignees array
if (Assignees == null)
{
Assignees = new List<string>();
}

Assignees.Add(name);
}

Expand All @@ -86,15 +76,7 @@ public void AddAssignee(string name)
/// </summary>
public void ClearAssignees()
{
// lazily create the assignees array
if (Assignees == null)
{
Assignees = new List<string>();
}
else
{
Assignees.Clear();
}
Assignees.Clear();
}

/// <summary>
Expand All @@ -103,15 +85,7 @@ public void ClearAssignees()
/// <param name="name">The login of the assignee to remove</param>
public void RemoveAssignee(string name)
{
// lazily create the assignees array
if (Assignees == null)
{
Assignees = new List<string>();
}
else
{
Assignees.Remove(name);
}
Assignees.Remove(name);
}

/// <summary>
Expand All @@ -120,12 +94,6 @@ public void RemoveAssignee(string name)
/// <param name="name">The name of the label.</param>
public void AddLabel(string name)
{
// lazily create the label array
if (Labels == null)
{
Labels = new List<string>();
}

Labels.Add(name);
}

Expand All @@ -134,15 +102,7 @@ public void AddLabel(string name)
/// </summary>
public void ClearLabels()
{
// lazily create the label array
if (Labels == null)
{
Labels = new List<string>();
}
else
{
Labels.Clear();
}
Labels.Clear();
}

/// <summary>
Expand All @@ -151,15 +111,7 @@ public void ClearLabels()
/// <param name="name">The name of the label to remove</param>
public void RemoveLabel(string name)
{
// lazily create the label array
if (Labels == null)
{
Labels = new List<string>();
}
else
{
Labels.Remove(name);
}
Labels.Remove(name);
}
}
}

0 comments on commit fc283af

Please sign in to comment.