@@ -31,6 +31,12 @@ public record FeatureFlag
3131 /// </summary>
3232 public bool IsEnabled { get ; init ; } = true ;
3333
34+ /// <summary>
35+ /// Whether this feature flag is linked to an experiment, as reported by the server.
36+ /// <c>null</c> when the server does not report it (older deployments).
37+ /// </summary>
38+ public bool ? HasExperiment { get ; init ; }
39+
3440 /// <summary>
3541 /// Creates a <see cref="FeatureFlag"/> instance from the <c>/flags</c> endpoint response. Since payloads are
3642 /// already calculated, we can look them up by the feature key.
@@ -44,10 +50,11 @@ internal static FeatureFlag CreateFromFlagsApi(
4450 FlagsApiResult apiResult )
4551 {
4652 var payload = NotNull ( apiResult ) . FeatureFlagPayloads ? . GetValueOrDefault ( key ) ;
53+ var flag = apiResult . Flags ? . GetValueOrDefault ( key ) ;
4754
48- var featureFlag = apiResult . Flags is not null && apiResult . Flags . TryGetValue ( key , out var flag )
49- && flag . Metadata is { Id : { } id , Version : { } version }
50- && flag . Reason ? . Description is { } reason
55+ var featureFlag = flag is not null
56+ && flag . Metadata is { Id : { } id , Version : { } version }
57+ && flag . Reason ? . Description is { } reason
5158 ? new FeatureFlagWithMetadata
5259 {
5360 Key = flag . Key ,
@@ -65,7 +72,8 @@ internal static FeatureFlag CreateFromFlagsApi(
6572 {
6673 IsEnabled = value . IsString ? value . StringValue is not null : value . Value ,
6774 VariantKey = value . StringValue ,
68- Payload = payload is null ? null : JsonDocument . Parse ( payload )
75+ Payload = payload is null ? null : JsonDocument . Parse ( payload ) ,
76+ HasExperiment = flag ? . Metadata ? . HasExperiment
6977 } ;
7078 }
7179
@@ -90,7 +98,8 @@ internal static FeatureFlag CreateFromLocalEvaluation(
9098 Key = key ,
9199 IsEnabled = value . IsString ? value . StringValue is not null : value . Value ,
92100 VariantKey = value . StringValue ,
93- Payload = payloadJsonString is null ? null : JsonDocument . Parse ( payloadJsonString )
101+ Payload = payloadJsonString is null ? null : JsonDocument . Parse ( payloadJsonString ) ,
102+ HasExperiment = localFeatureFlag . HasExperiment
94103 } ;
95104 }
96105
@@ -104,13 +113,14 @@ other is not null
104113 && Key == other . Key
105114 && IsEnabled == other . IsEnabled
106115 && VariantKey == other . VariantKey
116+ && HasExperiment == other . HasExperiment
107117 && JsonEqual ( Payload , other . Payload ) ;
108118
109119 /// <summary>
110120 /// Serves as the default hash function.
111121 /// </summary>
112122 /// <returns>A hash code for the current <see cref="FeatureFlag"/>.</returns>
113- public override int GetHashCode ( ) => HashCode . Combine ( Key , IsEnabled , VariantKey , Payload ) ;
123+ public override int GetHashCode ( ) => HashCode . Combine ( Key , IsEnabled , VariantKey , HasExperiment , Payload ) ;
114124
115125 static bool JsonEqual ( JsonDocument ? source , JsonDocument ? comparand ) =>
116126 JsonNode . DeepEquals ( ToJsonNode ( source ) , ToJsonNode ( comparand ) ) ;
0 commit comments