@@ -37,9 +37,18 @@ public partial class EvaluationContext<SegmentMetadataT, FeatureMetadataT>
3737 [ JsonProperty ( "segments" , Required = Required . DisallowNull , NullValueHandling = NullValueHandling . Ignore ) ]
3838 public Dictionary < string , SegmentContext < SegmentMetadataT , FeatureMetadataT > > Segments { get ; set ; }
3939
40+
41+ /// <summary>
42+ /// Creates a copy of the EvaluationContext object
43+ /// for internal use in the engine.
44+ /// Optimised to avoid deep cloning where possible.
45+ /// </summary>
46+ /// <returns>EvaluationContext</returns>
4047 public EvaluationContext < SegmentMetadataT , FeatureMetadataT > Clone ( )
4148 {
42- return ( EvaluationContext < SegmentMetadataT , FeatureMetadataT > ) MemberwiseClone ( ) ;
49+ var clone = ( EvaluationContext < SegmentMetadataT , FeatureMetadataT > ) MemberwiseClone ( ) ;
50+ clone . Identity = clone . Identity ? . Clone ( ) ;
51+ return clone ;
4352 }
4453 }
4554
@@ -166,6 +175,16 @@ public partial class IdentityContext
166175 /// </summary>
167176 [ JsonProperty ( "traits" , Required = Required . DisallowNull , NullValueHandling = NullValueHandling . Ignore ) ]
168177 public Dictionary < string , object > Traits { get ; set ; }
178+
179+ /// <summary>
180+ /// Creates a copy of the IdentityContext object
181+ /// for internal use in the engine.
182+ /// </summary>
183+ /// <returns>IdentityContext</returns>
184+ public IdentityContext Clone ( )
185+ {
186+ return ( IdentityContext ) MemberwiseClone ( ) ;
187+ }
169188 }
170189
171190 /// <summary>
0 commit comments