Skip to content

Commit

Permalink
fix(build): Resolve MultiTarget framework build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
arttonoyan committed Oct 14, 2024
1 parent 63ead66 commit 70708ec
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 11 deletions.
2 changes: 1 addition & 1 deletion OpenFeature.sln
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenFeature.DependencyInjec
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenFeature.DependencyInjection.Tests", "test\OpenFeature.DependencyInjection.Tests\OpenFeature.DependencyInjection.Tests.csproj", "{EB35F9F6-8A79-410E-A293-9387BC4AC9A7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFeature.Hosting", "src\OpenFeature.Hosting\OpenFeature.Hosting.csproj", "{C99DA02A-3981-45A6-B3F8-4A1A48653DEE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenFeature.Hosting", "src\OpenFeature.Hosting\OpenFeature.Hosting.csproj", "{C99DA02A-3981-45A6-B3F8-4A1A48653DEE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @formatter:off
// ReSharper disable All
#if NETCOREAPP3_0_OR_GREATER
// https://github.com/dotnet/runtime/issues/96197
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.CompilerServices.CallerArgumentExpressionAttribute))]
#else
#pragma warning disable
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
internal sealed class CallerArgumentExpressionAttribute : Attribute
{
public CallerArgumentExpressionAttribute(string parameterName)
{
ParameterName = parameterName;
}

public string ParameterName { get; }
}
#endif
20 changes: 20 additions & 0 deletions src/OpenFeature.DependencyInjection/MultiTarget/Guard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace OpenFeature;

[DebuggerStepThrough]
internal static class Guard
{
public static T ThrowIfNull<T>(T? value, [CallerArgumentExpression("value")] string name = null!)
{
#if NET8_0_OR_GREATER
ArgumentNullException.ThrowIfNull(value, name);
#else
if (value is null)
throw new ArgumentNullException(name);
#endif

return value;
}
}
21 changes: 21 additions & 0 deletions src/OpenFeature.DependencyInjection/MultiTarget/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @formatter:off
// ReSharper disable All
#if NET5_0_OR_GREATER
// https://github.com/dotnet/runtime/issues/96197
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.CompilerServices.IsExternalInit))]
#else
#pragma warning disable
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;

namespace System.Runtime.CompilerServices;

/// <summary>
/// Reserved to be used by the compiler for tracking metadata.
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
static class IsExternalInit { }
#endif
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net8.0;net462</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>OpenFeature</RootNamespace>
Expand All @@ -24,4 +24,8 @@
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<Folder Include="MultiTarget\" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/OpenFeature.DependencyInjection/OpenFeatureBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace OpenFeature;
/// <summary>
/// Describes a <see cref="OpenFeatureBuilder"/> backed by an <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="Services"><see cref="IServiceCollection"/></param>
/// <param name="Services">The <see cref="IServiceCollection"/> instance.</param>
public sealed record OpenFeatureBuilder(IServiceCollection Services)
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static OpenFeatureBuilder AddContext(
this OpenFeatureBuilder builder,
Action<EvaluationContextBuilder> configure)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configure);
Guard.ThrowIfNull(builder);
Guard.ThrowIfNull(configure);

return builder.AddContext((b, _) => configure(b));
}
Expand All @@ -34,8 +34,8 @@ public static OpenFeatureBuilder AddContext(
this OpenFeatureBuilder builder,
Action<EvaluationContextBuilder, IServiceProvider> configure)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configure);
Guard.ThrowIfNull(builder);
Guard.ThrowIfNull(configure);

builder.IsContextConfigured = true;
builder.Services.TryAddTransient(provider =>
Expand All @@ -58,7 +58,7 @@ public static OpenFeatureBuilder AddContext(
public static OpenFeatureBuilder AddProvider<T>(this OpenFeatureBuilder builder, Func<IServiceProvider, T> providerFactory)
where T : FeatureProvider
{
ArgumentNullException.ThrowIfNull(builder);
Guard.ThrowIfNull(builder);
builder.Services.TryAddSingleton<FeatureProvider>(providerFactory);
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static class OpenFeatureServiceCollectionExtensions
/// <returns>the current <see cref="IServiceCollection"/> instance</returns>
public static IServiceCollection AddOpenFeature(this IServiceCollection services, Action<OpenFeatureBuilder> configure)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configure);
Guard.ThrowIfNull(services);
Guard.ThrowIfNull(configure);

services.TryAddSingleton(Api.Instance);
services.TryAddSingleton<IFeatureLifecycleManager, FeatureLifecycleManager>();
Expand Down

0 comments on commit 70708ec

Please sign in to comment.