< Summary

Information
Class: IceRpc.Features.IceFeature
Assembly: IceRpc.Ice
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Ice/Features/IceFeature.cs
Tag: 2300_35243572715
Line coverage
66%
Covered lines: 34
Uncovered lines: 17
Coverable lines: 51
Total lines: 115
Line coverage: 66.6%
Branch coverage
50%
Covered branches: 17
Total branches: 34
Branch coverage: 50%
Method coverage
92%
Covered methods: 13
Fully covered methods: 12
Total methods: 14
Method coverage: 92.8%
Full method coverage: 85.7%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Default()100%11100%
get_Activator()100%11100%
get_BaseProxy()100%11100%
get_EncodeOptions()100%210%
get_MaxCollectionAllocation()100%11100%
get_MaxDepth()100%11100%
get_MaxPayloadSize()100%11100%
.ctor(...)50%1203457.89%
get_Activator()100%11100%
get_BaseProxy()100%11100%
get_EncodeOptions()100%11100%
get_MaxCollectionAllocation()100%11100%
get_MaxDepth()100%11100%
get_MaxPayloadSize()100%11100%

File(s)

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

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Ice;
 4using IceRpc.Ice.Codec;
 5
 6namespace IceRpc.Features;
 7
 8/// <summary>Default implementation of <see cref="IIceFeature" />.</summary>
 9public sealed class IceFeature : IIceFeature
 10{
 11    /// <summary>Gets a <see cref="IIceFeature" /> with default values for all properties.</summary>
 26812    public static IIceFeature Default { get; } = new DefaultIceFeature();
 13
 14    /// <inheritdoc/>
 115    public IActivator? Activator { get; }
 16
 17    /// <inheritdoc/>
 118    public IIceProxy? BaseProxy { get; }
 19
 20    /// <inheritdoc/>
 021    public IceEncodeOptions? EncodeOptions { get; }
 22
 23    /// <inheritdoc/>
 24    /// <value>The maximum collection allocation. Defaults to 8 times <see cref="MaxPayloadSize" />.</value>
 125    public int MaxCollectionAllocation { get; }
 26
 27    /// <inheritdoc/>
 28    /// <value>The maximum depth. Defaults to <c>100</c>.</value>
 129    public int MaxDepth { get; }
 30
 31    /// <inheritdoc/>
 32    /// <value>The maximum size of an Ice-encoded payload, in bytes. Defaults to <c>1</c> MB.</value>
 133    public int MaxPayloadSize { get; }
 34
 35    /// <summary>Constructs an Ice feature.</summary>
 36    /// <param name="activator">The activator.</param>
 37    /// <param name="encodeOptions">The encode options.</param>
 38    /// <param name="maxCollectionAllocation">The maximum collection allocation. Use <c>-1</c> to get the default value:
 39    /// 8 times <paramref name="maxPayloadSize" /> if set, otherwise the value provided by
 40    /// <paramref name="defaultFeature" />.</param>
 41    /// <param name="maxDepth">The maximum depth. Use <c>-1</c> to get the default value.</param>
 42    /// <param name="maxPayloadSize">The maximum size of an Ice-encoded payload, in bytes. Use <c>-1</c> to get the
 43    /// default value.</param>
 44    /// <param name="baseProxy">The base proxy, used when decoding service addresses into proxies.</param>
 45    /// <param name="defaultFeature">A feature that provides default values for all parameters. <see langword="null" />
 46    /// is equivalent to <see cref="Default" />.</param>
 47    /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="maxCollectionAllocation" /> is a
 48    /// negative value other than <c>-1</c>, when <paramref name="maxDepth" /> is <c>0</c> or a negative value other
 49    /// than <c>-1</c>, when <paramref name="maxPayloadSize" /> is <see cref="int.MaxValue" /> or a negative value other
 50    /// than <c>-1</c>, or when <paramref name="maxPayloadSize" /> is greater than <c>int.MaxValue / 8</c>
 51    /// (256 MB) while <paramref name="maxCollectionAllocation" /> is <c>-1</c>.</exception>
 152    public IceFeature(
 153        IActivator? activator = null,
 154        IceEncodeOptions? encodeOptions = null,
 155        int maxCollectionAllocation = -1,
 156        int maxDepth = -1,
 157        int maxPayloadSize = -1,
 158        IIceProxy? baseProxy = null,
 159        IIceFeature? defaultFeature = null)
 160    {
 161        if (maxCollectionAllocation < -1)
 062        {
 063            throw new ArgumentOutOfRangeException(
 064                nameof(maxCollectionAllocation),
 065                $"The value of {nameof(maxCollectionAllocation)} must be greater than or equal to 0, or -1.");
 66        }
 167        if (maxDepth is < -1 or 0)
 068        {
 069            throw new ArgumentOutOfRangeException(
 070                nameof(maxDepth),
 071                $"The value of {nameof(maxDepth)} must be greater than 0, or -1.");
 72        }
 173        if (maxPayloadSize is < -1 or int.MaxValue)
 074        {
 075            throw new ArgumentOutOfRangeException(
 076                nameof(maxPayloadSize),
 077                $"The value of {nameof(maxPayloadSize)} must be greater than or equal to 0 and less than int.MaxValue, o
 78        }
 179        if (maxCollectionAllocation == -1 && maxPayloadSize > int.MaxValue / 8)
 080        {
 081            throw new ArgumentOutOfRangeException(
 082                nameof(maxPayloadSize),
 083                $"The value of {nameof(maxPayloadSize)} must be less than or equal to int.MaxValue / 8 when {nameof(maxC
 84        }
 85
 186        defaultFeature ??= Default;
 87
 188        Activator = activator ?? defaultFeature.Activator;
 189        EncodeOptions = encodeOptions ?? defaultFeature.EncodeOptions;
 90
 191        MaxCollectionAllocation = maxCollectionAllocation >= 0 ? maxCollectionAllocation :
 192            (maxPayloadSize >= 0 ? 8 * maxPayloadSize : defaultFeature.MaxCollectionAllocation);
 93
 194        MaxDepth = maxDepth > 0 ? maxDepth : defaultFeature.MaxDepth;
 95
 196        MaxPayloadSize = maxPayloadSize >= 0 ? maxPayloadSize : defaultFeature.MaxPayloadSize;
 97
 198        BaseProxy = baseProxy ?? defaultFeature.BaseProxy;
 199    }
 100
 101    private class DefaultIceFeature : IIceFeature
 102    {
 193103        public IActivator? Activator => null;
 104
 132105        public IIceProxy? BaseProxy => null;
 106
 1107        public IceEncodeOptions? EncodeOptions => null;
 108
 133109        public int MaxCollectionAllocation => 8 * MaxPayloadSize;
 110
 133111        public int MaxDepth => 100;
 112
 382113        public int MaxPayloadSize => 1024 * 1024;
 114    }
 115}