< Summary

Information
Class: Ice.Object
Assembly: Ice
File(s): /_/csharp/src/Ice/Object.cs
Tag: 91_21789722663
Line coverage
76%
Covered lines: 29
Uncovered lines: 9
Coverable lines: 38
Total lines: 176
Line coverage: 76.3%
Branch coverage
66%
Covered branches: 16
Total branches: 24
Branch coverage: 66.6%
Method coverage
80%
Covered methods: 8
Total methods: 10
Method coverage: 80%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
dispatchAsync(...)0%7280%
ice_isA(...)100%66100%
ice_ping(...)100%11100%
ice_ids(...)100%44100%
ice_id(...)100%210%
ice_staticId()100%11100%
iceD_ice_isAAsync(...)100%22100%
iceD_ice_pingAsync(...)100%11100%
iceD_ice_idsAsync(...)100%22100%
iceD_ice_idAsync(...)100%22100%

File(s)

/_/csharp/src/Ice/Object.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3#nullable enable
 4
 5using System.ComponentModel;
 6
 7namespace Ice;
 8
 9/// <summary>
 10/// The base interface for servants.
 11/// </summary>
 12[SliceTypeId("::Ice::Object")]
 13public interface Object
 14{
 15    /// <summary>
 16    /// Dispatches an incoming request and returns the corresponding outgoing response.
 17    /// </summary>
 18    /// <param name="request">The incoming request.</param>
 19    /// <returns>A value task that holds the outgoing response.</returns>
 20    /// <remarks>If an exception is thrown, Ice will marshal it as the response payload.</remarks>
 21    public ValueTask<OutgoingResponse> dispatchAsync(IncomingRequest request) =>
 022        request.current.operation switch
 023        {
 024            "ice_id" => iceD_ice_idAsync(this, request),
 025            "ice_ids" => iceD_ice_idsAsync(this, request),
 026            "ice_isA" => iceD_ice_isAAsync(this, request),
 027            "ice_ping" => iceD_ice_pingAsync(this, request),
 028            _ => throw new OperationNotExistException()
 029        };
 30
 31    /// <summary>
 32    /// Tests whether this object supports a specific Slice interface.
 33    /// </summary>
 34    ///
 35    /// <param name="s">The type ID of the Slice interface to test against.</param>
 36    /// <param name="current">The Current object of the incoming request.</param>
 37    /// <returns><see langword="true"/> if this object implements the Slice interface specified by <paramref name="s"/>
 38    /// or implements a derived interface, <see langword="false"/> otherwise.</returns>
 39    public bool ice_isA(string s, Current current)
 40    {
 141        foreach (Type type in GetType().GetInterfaces())
 42        {
 143            if (type.GetSliceTypeId() is string typeId && typeId == s)
 44            {
 145                return true;
 46            }
 47        }
 148        return false;
 49    }
 50
 51    /// <summary>
 52    /// Tests whether this object can be reached.
 53    /// </summary>
 54    /// <param name="current">The Current object of the incoming request.</param>
 55    public void ice_ping(Current current)
 56    {
 57        // does nothing
 158    }
 59
 60    /// <summary>
 61    /// Returns the Slice interfaces supported by this object as a list of Slice type IDs.
 62    /// </summary>
 63    /// <param name="current">The Current object of the incoming request.</param>
 64    /// <returns>The Slice type IDs of the interfaces supported by this object, in alphabetical order.</returns>
 65    public string[] ice_ids(Current current)
 66    {
 167        var sortedSet = new SortedSet<string>(StringComparer.Ordinal);
 168        foreach (Type type in GetType().GetInterfaces())
 69        {
 170            if (type.GetSliceTypeId() is string typeId)
 71            {
 172                sortedSet.Add(typeId);
 73            }
 74        }
 175        return sortedSet.ToArray();
 76    }
 77
 78    /// <summary>
 79    /// Returns the type ID of the most-derived Slice interface supported by this object.
 80    /// </summary>
 81    /// <param name="current">The Current object of the incoming request.</param>
 82    /// <returns>The Slice type ID of the most-derived interface.</returns>
 083    public string ice_id(Current current) => ice_staticId();
 84
 85    /// <summary>
 86    /// Returns the type ID of the associated Slice interface.
 87    /// </summary>
 88    /// <returns>The return value is always <c>"::Ice::Object"</c>.</returns>
 189    public static string ice_staticId() => "::Ice::Object";
 90
 91    [EditorBrowsable(EditorBrowsableState.Never)]
 92    protected static ValueTask<OutgoingResponse> iceD_ice_isAAsync(Object obj, IncomingRequest request)
 93    {
 194        InputStream istr = request.inputStream;
 195        istr.startEncapsulation();
 196        string iceP_id = istr.readString();
 197        istr.endEncapsulation();
 198        bool ret = obj.ice_isA(iceP_id, request.current);
 199        return new(request.current.createOutgoingResponse(ret, static (ostr, ret) => ostr.writeBool(ret)));
 100    }
 101
 102    [EditorBrowsable(EditorBrowsableState.Never)]
 103    protected static ValueTask<OutgoingResponse> iceD_ice_pingAsync(Object obj, IncomingRequest request)
 104    {
 1105        InputStream istr = request.inputStream;
 1106        istr.skipEmptyEncapsulation();
 1107        obj.ice_ping(request.current);
 1108        return new(request.current.createEmptyOutgoingResponse());
 109    }
 110
 111    [EditorBrowsable(EditorBrowsableState.Never)]
 112    protected static ValueTask<OutgoingResponse> iceD_ice_idsAsync(Object obj, IncomingRequest request)
 113    {
 1114        InputStream istr = request.inputStream;
 1115        istr.skipEmptyEncapsulation();
 1116        string[] ret = obj.ice_ids(request.current);
 1117        return new(request.current.createOutgoingResponse(ret, static (ostr, ret) => ostr.writeStringSeq(ret)));
 118    }
 119
 120    [EditorBrowsable(EditorBrowsableState.Never)]
 121    protected static ValueTask<OutgoingResponse> iceD_ice_idAsync(Object obj, IncomingRequest request)
 122    {
 1123        InputStream istr = request.inputStream;
 1124        istr.skipEmptyEncapsulation();
 1125        string ret = obj.ice_id(request.current);
 1126        return new(request.current.createOutgoingResponse(ret, static (ostr, ret) => ostr.writeString(ret)));
 127    }
 128}
 129
 130/// <summary>
 131/// Base class for dynamic dispatch servants.
 132/// </summary>
 133/// <remarks>This class is provided for backward compatibility. You should consider deriving directly from
 134/// <see cref="Object"/> and overriding the <see cref="Object.dispatchAsync"/> method.</remarks>
 135public abstract class Blobject : Object
 136{
 137    /// <summary>
 138    /// Dispatches an incoming request.
 139    /// </summary>
 140    /// <param name="inParams">An encapsulation containing the encoded in-parameters for the operation.</param>
 141    /// <param name="outParams">An encapsulation containing the encoded result for the operation.</param>
 142    /// <param name="current">The Current object of the incoming request.</param>
 143    /// <returns><see langword="true"/> if the dispatch completes successfully, <see langword="false"/> if the dispatch
 144    /// completes with a user exception encoded in <paramref name="outParams"/>.</returns>
 145    public abstract bool ice_invoke(byte[] inParams, out byte[] outParams, Current current);
 146
 147    public ValueTask<OutgoingResponse> dispatchAsync(IncomingRequest request)
 148    {
 149        byte[] inEncaps = request.inputStream.readEncapsulation(out _);
 150        bool ok = ice_invoke(inEncaps, out byte[] outEncaps, request.current);
 151        return new(request.current.createOutgoingResponse(ok, outEncaps));
 152    }
 153}
 154
 155/// <summary>
 156/// Base class for asynchronous dynamic dispatch servants.
 157/// </summary>
 158/// <remarks>This class is provided for backward compatibility. You should consider deriving directly from
 159/// <see cref="Object"/> and overriding the <see cref="Object.dispatchAsync"/> method.</remarks>
 160public abstract class BlobjectAsync : Object
 161{
 162    /// <summary>
 163    /// Dispatches an incoming request.
 164    /// </summary>
 165    /// <param name="inEncaps">An encapsulation containing the encoded in-parameters for the operation.</param>
 166    /// <param name="current">The Current object of the incoming request.</param>
 167    /// <returns>A task that will complete with an instance of <see cref="Object_Ice_invokeResult"/>.</returns>
 168    public abstract Task<Object_Ice_invokeResult> ice_invokeAsync(byte[] inEncaps, Current current);
 169
 170    public async ValueTask<OutgoingResponse> dispatchAsync(IncomingRequest request)
 171    {
 172        byte[] inEncaps = request.inputStream.readEncapsulation(out _);
 173        Object_Ice_invokeResult result = await ice_invokeAsync(inEncaps, request.current).ConfigureAwait(false);
 174        return request.current.createOutgoingResponse(result.returnValue, result.outEncaps);
 175    }
 176}