• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

icerpc / icerpc-csharp / 20870171951

10 Jan 2026 01:03AM UTC coverage: 83.304% (-0.1%) from 83.399%
20870171951

Pull #4221

github

web-flow
Merge fe4f556d8 into f39e9819d
Pull Request #4221: Use new C#14 extension block syntax

12030 of 14441 relevant lines covered (83.3%)

2957.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
src/IceRpc.Protobuf/ProtobufServiceProviderExtensions.cs
1
// Copyright (c) ZeroC, Inc.
2

3
// TODO: temporary, for paramref. See #4220.
4
#pragma warning disable CS1734 // XML comment has a type parameter reference that is not valid.
5

6
namespace IceRpc.Protobuf;
7

8
/// <summary>Provides extension methods for <see cref="IServiceProvider" /> to create Protobuf clients.</summary>
9
public static class ProtobufServiceProviderExtensions
10
{
11
    /// <summary>Extension methods for <see cref="IServiceProvider" />.</summary>
12
    /// <param name="provider">The service provider.</param>
13
    extension(IServiceProvider provider)
14
    {
15
        /// <summary>Creates a Protobuf client with this service provider.</summary>
16
        /// <typeparam name="TClient">The Protobuf client struct.</typeparam>
17
        /// <param name="serviceAddress">The service address of the new client; null is equivalent to the default
18
        /// service address for the client type.</param>
19
        /// <returns>A new instance of <typeparamref name="TClient" />.</returns>
20
        /// <remarks>The new client uses the <see cref="IInvoker" /> retrieved from <paramref name="provider" />
21
        /// as its invocation pipeline, and the <see cref="ProtobufEncodeOptions" /> retrieved from
22
        /// <paramref name="provider" /> as its encode options.</remarks>
23
        public TClient CreateProtobufClient<TClient>(ServiceAddress? serviceAddress = null)
24
            where TClient : struct, IProtobufClient
25
        {
2✔
26
            var invoker = (IInvoker?)provider.GetService(typeof(IInvoker));
2✔
27
            if (invoker is null)
2✔
28
            {
1✔
29
                throw new InvalidOperationException(
1✔
30
                    "Could not find service of type 'IInvoker' in the service container.");
1✔
31
            }
32

33
            return serviceAddress is null ?
1✔
34
                new TClient
1✔
35
                {
1✔
36
                    EncodeOptions = (ProtobufEncodeOptions?)provider.GetService(typeof(ProtobufEncodeOptions)),
1✔
37
                    Invoker = invoker
1✔
38
                }
1✔
39
                :
1✔
40
                new TClient
1✔
41
                {
1✔
42
                    EncodeOptions = (ProtobufEncodeOptions?)provider.GetService(typeof(ProtobufEncodeOptions)),
1✔
43
                    Invoker = invoker,
1✔
44
                    ServiceAddress = serviceAddress
1✔
45
                };
1✔
46
        }
47

48
        /// <summary>Creates a Protobuf client with this service provider.</summary>
49
        /// <typeparam name="TClient">The Protobuf client struct.</typeparam>
50
        /// <param name="serviceAddressUri">The service address of the client as a URI.</param>
51
        /// <returns>A new instance of <typeparamref name="TClient" />.</returns>
52
        /// <remarks>The new client uses the <see cref="IInvoker" /> retrieved from <paramref name="provider" />
53
        /// as its invocation pipeline, and the <see cref="ProtobufEncodeOptions" /> retrieved from
54
        /// <paramref name="provider" /> as its encode options.</remarks>
55
        public TClient CreateProtobufClient<TClient>(Uri serviceAddressUri)
56
            where TClient : struct, IProtobufClient =>
57
            provider.CreateProtobufClient<TClient>(new ServiceAddress(serviceAddressUri));
×
58
    }
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc