< Summary

Information
Class: IceRpc.Ice.IceProxyExtensions
Assembly: IceRpc.Ice
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Ice/IceProxyExtensions.cs
Tag: 1321_24790053727
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 37
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage
100%
Covered methods: 2
Fully covered methods: 2
Total methods: 2
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToProxy(...)100%11100%
AsAsync()100%22100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Ice/IceProxyExtensions.cs

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