UNPKG

@autorest/powershell

Version:
67 lines 3.75 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.Duration = void 0; const codemodel_v3_1 = require("@azure-tools/codemodel-v3"); const codegen_csharp_1 = require("@azure-tools/codegen-csharp"); const primitive_1 = require("./primitive"); const clientruntime_1 = require("../clientruntime"); class Duration extends primitive_1.NewPrimitive { constructor(schema, isRequired) { super(schema); this.schema = schema; this.isRequired = isRequired; this.isXmlAttribute = false; this.jsonType = clientruntime_1.ClientRuntime.JsonString; } get encode() { return (this.schema.extensions && this.schema.extensions['x-ms-skip-url-encoding']) ? '' : 'global::System.Uri.EscapeDataString'; } get declaration() { return `global::System.TimeSpan${this.isRequired ? '' : '?'}`; } castJsonTypeToPrimitive(tmpValue, defaultValue) { return `global::System.Xml.XmlConvert.ToTimeSpan( ${tmpValue} )`; } get convertObjectMethod() { return '(v) => v is global::System.TimeSpan _v ? _v : global::System.Xml.XmlConvert.ToTimeSpan( v.ToString() )'; } serializeToNode(mediaType, value, serializedName, mode) { switch (mediaType) { case codemodel_v3_1.KnownMediaType.Json: if (!this.isRequired) { return (0, codegen_csharp_1.toExpression)(`(null != ${value} ? ${clientruntime_1.ClientRuntime.JsonString.new(`global::System.Xml.XmlConvert.ToString((global::System.TimeSpan)${value})`)}: null)`).Cast(clientruntime_1.ClientRuntime.JsonNode); } return (0, codegen_csharp_1.toExpression)(`${clientruntime_1.ClientRuntime.JsonString.new(`global::System.Xml.XmlConvert.ToString((global::System.TimeSpan)${value})`)}`).Cast(clientruntime_1.ClientRuntime.JsonNode); case codemodel_v3_1.KnownMediaType.QueryParameter: { const formatSerializedName = serializedName ? `${serializedName}=` : ''; if (this.isRequired) { return (0, codegen_csharp_1.toExpression)(`"${formatSerializedName}" + ${this.encode}(global::System.Xml.XmlConvert.ToString((global::System.TimeSpan)${value}))`); } else { return (0, codegen_csharp_1.toExpression)(`(null == ${value} ? ${codegen_csharp_1.System.String.Empty} : "${formatSerializedName}" + ${this.encode}(global::System.Xml.XmlConvert.ToString((global::System.TimeSpan)${value})))`); } } } return (0, codegen_csharp_1.toExpression)(`/* serializeToNode doesn't support '${mediaType}' ${__filename}*/`); } serializeToContainerMember(mediaType, value, container, serializedName, mode) { switch (mediaType) { case codemodel_v3_1.KnownMediaType.Json: // container : JsonObject return `AddIf( ${this.serializeToNode(mediaType, value, serializedName, mode)}, "${serializedName}" ,${(0, codegen_csharp_1.valueOf)(container)}.Add );`; } return (`/* serializeToContainerMember doesn't support '${mediaType}' ${__filename}*/`); } validateValue(eventListener, property) { return ''; } validatePresence(eventListener, property) { return ''; } } exports.Duration = Duration; //# sourceMappingURL=duration.js.map