Skip to content

Commit

Permalink
Apply #if/#else patch for lower TFMs
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Drenski <austin@austindrenski.io>
  • Loading branch information
austindrenski committed Jan 17, 2024
1 parent 659a8d9 commit db49121
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/OpenFeature/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,26 @@ public FeatureClient GetClient(string name = null, string version = null, ILogge
/// </para>
/// </summary>
/// <param name="hooks">A list of <see cref="Hook"/></param>
public void AddHooks(IEnumerable<Hook> hooks) => this._hooks.PushRange(hooks.ToArray());
public void AddHooks(IEnumerable<Hook> hooks)
#if NET7_0_OR_GREATER
=> this._hooks.PushRange(hooks as Hook[] ?? hooks.ToArray());
#else
{
// See: https://github.com/dotnet/runtime/issues/62121
if (hooks is Hook[] array)
{
if (array.Length > 0)
this._hooks.PushRange(array);

return;
}

array = hooks.ToArray();

if (array.Length > 0)
this._hooks.PushRange(array);

Check warning on line 147 in src/OpenFeature/Api.cs

View check run for this annotation

Codecov / codecov/patch

src/OpenFeature/Api.cs#L147

Added line #L147 was not covered by tests
}
#endif

/// <summary>
/// Adds a hook to global hooks list
Expand Down
21 changes: 20 additions & 1 deletion src/OpenFeature/OpenFeatureClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,26 @@ public void RemoveHandler(ProviderEventTypes type, EventHandlerDelegate handler)
}

/// <inheritdoc />
public void AddHooks(IEnumerable<Hook> hooks) => this._hooks.PushRange(hooks.ToArray());
public void AddHooks(IEnumerable<Hook> hooks)
#if NET7_0_OR_GREATER
=> this._hooks.PushRange(hooks as Hook[] ?? hooks.ToArray());
#else
{
// See: https://github.com/dotnet/runtime/issues/62121
if (hooks is Hook[] array)
{
if (array.Length > 0)
this._hooks.PushRange(array);

return;
}

array = hooks.ToArray();

Check warning on line 123 in src/OpenFeature/OpenFeatureClient.cs

View check run for this annotation

Codecov / codecov/patch

src/OpenFeature/OpenFeatureClient.cs#L123

Added line #L123 was not covered by tests

if (array.Length > 0)
this._hooks.PushRange(array);

Check warning on line 126 in src/OpenFeature/OpenFeatureClient.cs

View check run for this annotation

Codecov / codecov/patch

src/OpenFeature/OpenFeatureClient.cs#L126

Added line #L126 was not covered by tests
}
#endif

/// <inheritdoc />
public IEnumerable<Hook> GetHooks() => this._hooks.Reverse();
Expand Down

0 comments on commit db49121

Please sign in to comment.