11using System ;
22using System . Threading . Tasks ;
3+ using Temporalio . Converters ;
34
45namespace Temporalio . Client
56{
@@ -10,7 +11,13 @@ namespace Temporalio.Client
1011 /// <param name="Activity">Reference to the activity for this handle.</param>
1112 public record AsyncActivityHandle (
1213 ITemporalClient Client , AsyncActivityHandle . Reference Activity )
14+ : IWithSerializationContext < AsyncActivityHandle >
1315 {
16+ /// <summary>
17+ /// Gets or inits the data converter that will be used instead of the clients if set.
18+ /// </summary>
19+ public DataConverter ? DataConverterOverride { get ; init ; }
20+
1421 /// <summary>
1522 /// Issue a heartbeat for this activity.
1623 /// </summary>
@@ -22,7 +29,7 @@ public record AsyncActivityHandle(
2229 /// </exception>
2330 public Task HeartbeatAsync ( AsyncActivityHeartbeatOptions ? options = null ) =>
2431 Client . OutboundInterceptor . HeartbeatAsyncActivityAsync ( new (
25- Activity : Activity , Options : options ) ) ;
32+ Activity : Activity , Options : options , DataConverterOverride : DataConverterOverride ) ) ;
2633
2734 /// <summary>
2835 /// Complete this activity.
@@ -33,7 +40,7 @@ public Task HeartbeatAsync(AsyncActivityHeartbeatOptions? options = null) =>
3340 public Task CompleteAsync (
3441 object ? result = null , AsyncActivityCompleteOptions ? options = null ) =>
3542 Client . OutboundInterceptor . CompleteAsyncActivityAsync ( new (
36- Activity : Activity , Result : result , Options : options ) ) ;
43+ Activity : Activity , Result : result , Options : options , DataConverterOverride : DataConverterOverride ) ) ;
3744
3845 /// <summary>
3946 /// Fail this activity.
@@ -43,7 +50,7 @@ public Task CompleteAsync(
4350 /// <returns>Completion task.</returns>
4451 public Task FailAsync ( Exception exception , AsyncActivityFailOptions ? options = null ) =>
4552 Client . OutboundInterceptor . FailAsyncActivityAsync ( new (
46- Activity : Activity , Exception : exception , Options : options ) ) ;
53+ Activity : Activity , Exception : exception , Options : options , DataConverterOverride : DataConverterOverride ) ) ;
4754
4855 /// <summary>
4956 /// Report this activity as cancelled.
@@ -53,7 +60,25 @@ public Task FailAsync(Exception exception, AsyncActivityFailOptions? options = n
5360 public Task ReportCancellationAsync (
5461 AsyncActivityReportCancellationOptions ? options = null ) =>
5562 Client . OutboundInterceptor . ReportCancellationAsyncActivityAsync ( new (
56- Activity : Activity , Options : options ) ) ;
63+ Activity : Activity , Options : options , DataConverterOverride : DataConverterOverride ) ) ;
64+
65+ /// <summary>
66+ /// If the data converter supports customizing based on serialization context, recreate this
67+ /// handle with a data converter override using the given context.
68+ /// </summary>
69+ /// <param name="context">Context to provide to data converter.</param>
70+ /// <returns>New handle if context supported on data converter, same handle otherwise.</returns>
71+ public AsyncActivityHandle WithSerializationContext ( ISerializationContext context )
72+ {
73+ var converter = DataConverterOverride ?? Client . Options . DataConverter ;
74+ var newConverter = converter . WithSerializationContext ( context ) ;
75+ // Don't do anything if same object
76+ if ( ReferenceEquals ( converter , newConverter ) )
77+ {
78+ return this ;
79+ }
80+ return this with { DataConverterOverride = newConverter } ;
81+ }
5782
5883 /// <summary>
5984 /// Reference to an existing activity.
0 commit comments