microsoft / FeatureManagement-Dotnet

Microsoft.FeatureManagement provides standardized APIs for enabling feature flags within applications. Utilize this library to secure a consistent experience when developing applications that use patterns such as beta access, rollout, dark deployments, and more.
MIT License
1.05k stars 115 forks source link

Stop using init-only setter for netstandard #450

Closed zhiyuanliang-ms closed 5 months ago

zhiyuanliang-ms commented 6 months ago

Why this PR?

435

Visible change

Replace init setter to set

zhenlan commented 6 months ago

Is it possible we can add test to make sure we are netstandard/netfx 4.x compatible?

zhiyuanliang-ms commented 6 months ago

Is it possible we can add test to make sure we are netstandard/netfx 4.x compatible?

Currently, the TargetFrameworks is netstand2.0 but the LangVersion is 9.0, maybe we should set the LangVersion to 7.3 or remove the LangVersion. https://github.com/microsoft/FeatureManagement-Dotnet/blob/main/src/Microsoft.FeatureManagement/Microsoft.FeatureManagement.csproj

I checked other .net libraries which targets on netstandard, I found they didn't specify the LangVersion https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Bcl.TimeProvider/src/Microsoft.Bcl.TimeProvider.csproj

Maybe, we should do the same thing.

zhiyuanliang-ms commented 6 months ago

@jimmyca15 @zhenlan

Maybe we should set the LangVersion to 8.0. The things get quite tricky here. We have an API: IAsyncEnumerable<string> GetFeatureNamesAsync() of IFeatureManager,

However, async stream is not available in C# 7.3 (need 8.0+), so the GetFeatureNamesAsync will not work for .NET framework app.

alexaka1 commented 6 months ago

The await foreach() syntax is exclusive to 8.0 and up, but you can still use the type manually in 7.3, getting an enumerator and calling next asynchronously in a while loop. https://learn.microsoft.com/en-us/archive/msdn-magazine/2019/november/csharp-iterating-with-async-enumerables-in-csharp-8#a-tour-through-async-enumerables https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1.getasyncenumerator?view=netframework-4.8#system-collections-generic-iasyncenumerable-1-getasyncenumerator(system-threading-cancellationtoken)

jimmyca15 commented 6 months ago

Using language version 8.0.0 would ensure we couldn't write init only setters. It also prevents us from taking advantage of new language features but that may be what makes sense since we are supporting netstandard.

zhiyuanliang-ms commented 5 months ago

/AzurePipeline run

zhiyuanliang-ms commented 5 months ago

/AzurePipeline run

azure-pipelines[bot] commented 5 months ago
Azure Pipelines successfully started running 1 pipeline(s).