Back to all reviewers

Feature flag implementation

dotnet/runtime
Based on 2 comments
C#

When implementing feature flags, ensure consistency between runtime and compiled scenarios. Feature switches marked with `FeatureSwitchDefinition` must properly return the AppContext switch value when defined:

Configurations C#

Reviewer Prompt

When implementing feature flags, ensure consistency between runtime and compiled scenarios. Feature switches marked with FeatureSwitchDefinition must properly return the AppContext switch value when defined:

// INCORRECT implementation
[FeatureSwitchDefinition("System.Net.SocketsHttpHandler.Http3Support")]
public static bool IsHttp3Supported => SomeDefaultLogic();

// CORRECT implementation - must use the AppContext switch value
[FeatureSwitchDefinition("System.Net.SocketsHttpHandler.Http3Support")]
public static bool IsHttp3Supported => 
    AppContext.TryGetSwitch("System.Net.SocketsHttpHandler.Http3Support", out var ret) ? ret : SomeDefaultLogic();

Consider dead code elimination implications when designing feature flags for AOT scenarios, as behavior differences may arise between dotnet run and dotnet publish. Avoid adding configuration switches preemptively - only introduce them when there’s a demonstrated need from users. For platform-specific features, ensure configuration is properly respected across all supported environments.

2
Comments Analyzed
C#
Primary Language
Configurations
Category

Source Discussions