UNPKG

@autorest/powershell

Version:
62 lines 3.47 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.ModelProperty = void 0; const codegen_csharp_1 = require("@azure-tools/codegen-csharp"); const codegen_csharp_2 = require("@azure-tools/codegen-csharp"); const codemodel_1 = require("@autorest/codemodel"); class ModelProperty extends codegen_csharp_2.BackedProperty { /** emits an expression to deserialize a property from a member inside a container */ deserializeFromContainerMember(mediaType, container, serializedName) { return this.typeDeclaration.deserializeFromContainerMember(mediaType, container, serializedName, this); } /** emits an expression to deserialze a container as the value itself. */ deserializeFromNode(mediaType, node) { return this.typeDeclaration.deserializeFromNode(mediaType, node, this); } /** emits an expression serialize this to the value required by the container */ serializeToNode(mediaType, serializedName, mode) { return this.typeDeclaration.serializeToNode(mediaType, this, serializedName, mode); } /** emits an expression serialize this to a HttpContent */ serializeToContent(mediaType, mode) { return this.typeDeclaration.serializeToContent(mediaType, this, mode); } /** emits the code required to serialize this into a container */ serializeToContainerMember(mediaType, container, serializedName, mode) { return this.typeDeclaration.serializeToContainerMember(mediaType, container, this, serializedName, mode); } validatePresenceStatement(eventListener) { if (this.required) { return this.type.validatePresence(eventListener, this); } return ''; } validationStatement(eventListener) { return this.type.validateValue(eventListener, this); } constructor(name, schema, isRequired, serializedName, description, state, objectInitializer) { var _a, _b; const decl = state.project.modelsNamespace.NewResolveTypeDeclaration(schema, isRequired, state.path('schema')); super(name, decl); this.typeDeclaration = decl; this.serializedName = serializedName; this.schema = schema; // skip-for-time-being // if (this.schema.readOnly) { // this.set = undefined; // } this.apply(objectInitializer); this.description = description; this.required = isRequired; if ((this.schema.type === codemodel_1.SchemaType.Object || this.schema.type === codemodel_1.SchemaType.Dictionary || this.schema.type === codemodel_1.SchemaType.Any) && (0, codegen_csharp_1.isAnExpression)(this.get) && ((_a = schema.language.csharp) === null || _a === void 0 ? void 0 : _a.classImplementation)) { // for objects, the getter should auto-create a new object this.get = (0, codegen_csharp_1.toExpression)(`(${this.get.value} = ${this.get.value} ?? new ${(_b = schema.language.csharp) === null || _b === void 0 ? void 0 : _b.fullname}())`); } } } exports.ModelProperty = ModelProperty; //# sourceMappingURL=property.js.map