< Summary

Information
Class: IceRpc.TypeExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/TypeExtensions.cs
Tag: 275_13775359185
Line coverage
57%
Covered lines: 8
Uncovered lines: 6
Coverable lines: 14
Total lines: 35
Line coverage: 57.1%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage
100%
Covered methods: 1
Total methods: 1
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetDefaultServicePath(...)50%8.83657.14%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/TypeExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3namespace IceRpc;
 4
 5/// <summary>Provides extension methods for <see cref="Type" />.</summary>
 6public static class TypeExtensions
 7{
 8    /// <summary>Retrieves the default service path with the attribute <see cref="DefaultServicePathAttribute"/>.
 9    /// </summary>
 10    /// <param name="type">The type of an interface.</param>
 11    /// <returns>The default service path.</returns>
 12    /// <exception cref="ArgumentException">Thrown if <paramref name="type" /> is not an interface, or if
 13    /// it does not have a <see cref="DefaultServicePathAttribute" /> attribute.</exception>
 14    public static string GetDefaultServicePath(this Type type)
 715    {
 716        if (type.IsInterface)
 717        {
 718            object[] attributes = type.GetCustomAttributes(typeof(DefaultServicePathAttribute), false);
 719            if (attributes.Length == 1 && attributes[0] is DefaultServicePathAttribute defaultServicePath)
 720            {
 721                return defaultServicePath.Value;
 22            }
 23            else
 024            {
 025                throw new ArgumentException(
 026                    $"Interface '{type}' does not have a {nameof(DefaultServicePathAttribute)} attribute.",
 027                    nameof(type));
 28            }
 29        }
 30        else
 031        {
 032            throw new ArgumentException($"The type '{type}' is not an interface.", nameof(type));
 33        }
 734    }
 35}