UNPKG

@autorest/powershell

Version:
78 lines 3.89 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); exports.Binary = void 0; const codemodel_v3_1 = require("@azure-tools/codemodel-v3"); const codegen_1 = require("@azure-tools/codegen"); const codegen_csharp_1 = require("@azure-tools/codegen-csharp"); const codegen_csharp_2 = require("@azure-tools/codegen-csharp"); class Binary { constructor(schema, isRequired) { this.schema = schema; this.isRequired = isRequired; this.isXmlAttribute = false; this.isNullable = true; } get convertObjectMethod() { return 'i=>i'; } get defaultOfType() { return (0, codegen_csharp_2.toExpression)('null /* binary type */'); } get declaration() { return codegen_csharp_1.System.IO.Stream.declaration; } /** emits an expression to deserialize a property from a member inside a container */ deserializeFromContainerMember(mediaType, container, serializedName, defaultValue) { if (mediaType === codemodel_v3_1.KnownMediaType.Stream) { // dunno. } if (mediaType === codemodel_v3_1.KnownMediaType.Json) { return (0, codegen_csharp_2.toExpression)('null /* no need to deserialize a stream here */ '); } return (0, codegen_csharp_2.toExpression)(`null /* deserializeFromContainerMember doesn't support '${mediaType}' ${__filename}*/`); } /** emits an expression to deserialze a container as the value itself. */ deserializeFromNode(mediaType, node, defaultValue) { return (0, codegen_csharp_2.toExpression)(`null /* deserializeFromNode doesn't support '${mediaType}' ${__filename}*/`); } /** emits an expression to deserialize content from a string */ deserializeFromString(mediaType, content, defaultValue) { return undefined; } /** emits an expression to deserialize content from a content/response */ deserializeFromResponse(mediaType, content, defaultValue) { return (0, codegen_csharp_2.toExpression)(`${(0, codegen_csharp_1.valueOf)(content)}.Content.ReadAsStreamAsync()`); } /** emits an expression serialize this to the value required by the container */ serializeToContent(mediaType, value, mode) { if (mediaType === codemodel_v3_1.KnownMediaType.Stream) { return (0, codegen_csharp_2.toExpression)(codegen_csharp_1.System.Net.Http.StreamContent.new(value)); } return (0, codegen_csharp_2.toExpression)(`null /* serializeToNode doesn't support '${mediaType}' ${__filename}*/`); } serializeToNode(mediaType, value, serializedName, mode) { return (0, codegen_csharp_2.toExpression)(`null /* serializeToNode doesn't support '${mediaType}' ${__filename}*/`); } /** emits the code required to serialize this into a container */ serializeToContainerMember(mediaType, value, container, serializedName, mode) { if (mediaType === codemodel_v3_1.KnownMediaType.Json) { return `/* shouldn't need to serialize binary for a ${mediaType} */`; } return `/* serializeToContainerMember doesn't support '${mediaType}' ${__filename}*/`; } validateValue(eventListener, property) { return ''; } validatePresence(eventListener, property) { if (this.isRequired) { return `await ${eventListener}.AssertNotNull(${(0, codegen_1.nameof)(property.value)},${property});`.trim(); } return ''; } } exports.Binary = Binary; //# sourceMappingURL=binary.js.map