Exemple #1
0
        /// <summary>
        /// Encodes the value returned by a procedure handler into a ByteString
        /// </summary>
        ByteString EncodeReturnValue(ProcedureSignature procedure, object returnValue)
        {
            // Check the return value is missing
            if (returnValue == null && !TypeUtils.IsAClassType(procedure.ReturnType))
            {
                throw new RPCException(
                          procedure,
                          procedure.FullyQualifiedName + " returned null. " +
                          "Expected an object of type " + procedure.ReturnType);
            }

            // Check if the return value is of a valid type
            if (!TypeUtils.IsAValidType(procedure.ReturnType))
            {
                throw new RPCException(
                          procedure,
                          procedure.FullyQualifiedName + " returned an object of an invalid type. " +
                          "Expected " + procedure.ReturnType + "; got " + returnValue.GetType());
            }

            // Encode it as a ByteString
            return(Encode(procedure.ReturnType, returnValue));
        }