< Summary

Information
Class: IceRpc.Slice.SliceServiceProviderExtensions
Assembly: IceRpc.Slice
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Slice/SliceServiceProviderExtensions.cs
Tag: 275_13775359185
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 52
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage
100%
Covered methods: 2
Total methods: 2
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CreateSliceProxy(...)75%44100%
CreateSliceProxy(...)100%11100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Slice/SliceServiceProviderExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3namespace IceRpc.Slice;
 4
 5/// <summary>Provides extension methods for <see cref="IServiceProvider" /> to create Slice proxies.</summary>
 6public static class SliceServiceProviderExtensions
 7{
 8    /// <summary>Creates a Slice proxy with this service provider.</summary>
 9    /// <typeparam name="TProxy">The Slice proxy struct.</typeparam>
 10    /// <param name="provider">The service provider.</param>
 11    /// <param name="serviceAddress">The service address of the new proxy; null is equivalent to the default service
 12    /// address for the proxy type.</param>
 13    /// <returns>A new instance of <typeparamref name="TProxy" />.</returns>
 14    /// <remarks>The new proxy uses the <see cref="IInvoker" /> retrieved from <paramref name="provider" /> as its
 15    /// invocation pipeline, and the <see cref="SliceEncodeOptions" /> retrieved from <paramref name="provider" /> as
 16    /// its encode options.</remarks>
 17    public static TProxy CreateSliceProxy<TProxy>(this IServiceProvider provider, ServiceAddress? serviceAddress = null)
 18        where TProxy : struct, IProxy
 619    {
 620        var invoker = (IInvoker?)provider.GetService(typeof(IInvoker));
 621        if (invoker is null)
 122        {
 123            throw new InvalidOperationException("Could not find service of type 'IInvoker' in the service container.");
 24        }
 25
 526        return serviceAddress is null ?
 527            new TProxy
 528            {
 529                EncodeOptions = (SliceEncodeOptions?)provider.GetService(typeof(SliceEncodeOptions)),
 530                Invoker = invoker
 531            }
 532            :
 533            new TProxy
 534            {
 535                EncodeOptions = (SliceEncodeOptions?)provider.GetService(typeof(SliceEncodeOptions)),
 536                Invoker = invoker,
 537                ServiceAddress = serviceAddress
 538            };
 539    }
 40
 41    /// <summary>Creates a Slice proxy with this service provider.</summary>
 42    /// <typeparam name="TProxy">The Slice proxy struct.</typeparam>
 43    /// <param name="provider">The service provider.</param>
 44    /// <param name="serviceAddressUri">The service address of the proxy as a URI.</param>
 45    /// <returns>A new instance of <typeparamref name="TProxy" />.</returns>
 46    /// <remarks>The new proxy uses the <see cref="IInvoker" /> retrieved from <paramref name="provider" /> as its
 47    /// invocation pipeline, and the <see cref="SliceEncodeOptions" /> retrieved from <paramref name="provider" /> as
 48    /// its encode options.</remarks>
 49    public static TProxy CreateSliceProxy<TProxy>(this IServiceProvider provider, Uri serviceAddressUri)
 50        where TProxy : struct, IProxy =>
 451        provider.CreateSliceProxy<TProxy>(new ServiceAddress(serviceAddressUri));
 52}