| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using IceRpc.Features; |
| | 4 | | using ZeroC.Slice; |
| | 5 | |
|
| | 6 | | namespace IceRpc.Slice.Ice; |
| | 7 | |
|
| | 8 | | /// <summary>Provides an extension method for interface <see cref="IProxy" />.</summary> |
| | 9 | | public static class ProxyExtensions |
| | 10 | | { |
| | 11 | | /// <summary>Tests whether the target service implements the Slice interface associated with |
| | 12 | | /// <typeparamref name="TProxy" />. This method is a wrapper for <see cref="IIceObject.IceIsAAsync" />. |
| | 13 | | /// All services implemented with Ice automatically provide this operation. Services implemented with IceRPC provide |
| | 14 | | /// this operation only when they implement Slice interface <c>Ice::Object</c> explicitly.</summary> |
| | 15 | | /// <typeparam name="TProxy">The type of the target proxy struct.</typeparam> |
| | 16 | | /// <param name="proxy">The source proxy being tested.</param> |
| | 17 | | /// <param name="features">The invocation features.</param> |
| | 18 | | /// <param name="cancellationToken">A cancellation token that receives the cancellation requests.</param> |
| | 19 | | /// <returns>A new <typeparamref name="TProxy" /> instance when <see cref="IIceObject.IceIsAAsync"/> returns |
| | 20 | | /// <see langword="true"/>; otherwise, <see langword="null" />.</returns> |
| | 21 | | /// <remarks>This method is equivalent to the "checked cast" methods provided by Ice. </remarks> |
| | 22 | | public static async Task<TProxy?> AsAsync<TProxy>( |
| | 23 | | this IProxy proxy, |
| | 24 | | IFeatureCollection? features = null, |
| | 25 | | CancellationToken cancellationToken = default) where TProxy : struct, IProxy => |
| 2 | 26 | | await proxy.ToProxy<IceObjectProxy>().IceIsAAsync(typeof(TProxy).GetSliceTypeId()!, features, cancellationToken) |
| 2 | 27 | | .ConfigureAwait(false) ? |
| 2 | 28 | | proxy.ToProxy<TProxy>() : null; |
| | 29 | | } |