UNPKG

@autorest/powershell

Version:
45 lines 6.6 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.implementIDictionary = void 0; const codegen_csharp_1 = require("@azure-tools/codegen-csharp"); function implementIDictionary(targetClass, name, keyType, valueType, accessViaMember) { const dictionaryInterfaceType = codegen_csharp_1.System.Collections.Generic.IDictionary(keyType, valueType); const itemType = codegen_csharp_1.System.Collections.Generic.KeyValuePair(keyType, valueType); const collectionInterfaceType = codegen_csharp_1.System.Collections.Generic.ICollection(itemType); const enumerableInterfaceType = codegen_csharp_1.System.Collections.Generic.IEnumerable(itemType); // add the interface to the list of interfaces for the class targetClass.interfaces.push(dictionaryInterfaceType); // the backing field const dictionaryType = codegen_csharp_1.System.Collections.Generic.Dictionary(keyType, valueType); accessViaMember = accessViaMember || targetClass.add(new codegen_csharp_1.Field(`__${name}`, dictionaryInterfaceType, { initialValue: dictionaryType.new() })); const indexer = targetClass.add(new codegen_csharp_1.Indexer(keyType, valueType, { get: (0, codegen_csharp_1.toExpression)(`${accessViaMember}["index"]`), set: (0, codegen_csharp_1.toExpression)(`${accessViaMember}["index"] = value`) })); // the parameters used in methods. const pKey = new codegen_csharp_1.Parameter('key', keyType); const pValue = new codegen_csharp_1.Parameter('value', valueType); const pItem = new codegen_csharp_1.Parameter('item', itemType); const pItemArray = new codegen_csharp_1.Parameter('items', codegen_csharp_1.dotnet.Array(itemType)); const pIndex = new codegen_csharp_1.Parameter('index', codegen_csharp_1.dotnet.Int); const pOutValue = new codegen_csharp_1.Parameter('value', valueType, { modifier: codegen_csharp_1.ParameterModifier.Out }); targetClass.add(new codegen_csharp_1.Property(`${dictionaryInterfaceType.declaration}.Keys`, codegen_csharp_1.System.Collections.Generic.ICollection(keyType), { get: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.Keys`), getAccess: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Property(`${dictionaryInterfaceType.declaration}.Values`, codegen_csharp_1.System.Collections.Generic.ICollection(valueType), { get: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.Values`), getAccess: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Property(`${collectionInterfaceType.declaration}.Count`, codegen_csharp_1.dotnet.Int, { get: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.Count`), getAccess: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Property(`${collectionInterfaceType.declaration}.IsReadOnly`, codegen_csharp_1.dotnet.Bool, { get: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.IsReadOnly`), getAccess: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Method(`${dictionaryInterfaceType.declaration}.Add`, codegen_csharp_1.dotnet.Void, { parameters: [pKey, pValue], body: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.Add( ${pKey}, ${pValue})`), access: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Method(`${collectionInterfaceType.declaration}.Add`, codegen_csharp_1.dotnet.Void, { parameters: [pItem], body: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.Add( ${pItem})`), access: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Method(`${collectionInterfaceType.declaration}.Clear`, codegen_csharp_1.dotnet.Void, { body: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.Clear()`), access: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Method(`${collectionInterfaceType.declaration}.Contains`, codegen_csharp_1.dotnet.Bool, { parameters: [pItem], body: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.Contains( ${pItem})`), access: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Method(`${dictionaryInterfaceType.declaration}.ContainsKey`, codegen_csharp_1.dotnet.Bool, { parameters: [pKey], body: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.ContainsKey( ${pKey})`), access: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Method(`${collectionInterfaceType.declaration}.CopyTo`, codegen_csharp_1.dotnet.Void, { parameters: [pItemArray, pIndex], body: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.CopyTo(${pItemArray},${pIndex})`), access: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Method(`${enumerableInterfaceType.declaration}.GetEnumerator`, codegen_csharp_1.System.Collections.Generic.IEnumerator(itemType), { body: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.GetEnumerator()`), access: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Method('global::System.Collections.IEnumerable.GetEnumerator', codegen_csharp_1.System.Collections.IEnumerator, { body: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.GetEnumerator()`), access: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Method(`${dictionaryInterfaceType.declaration}.Remove`, codegen_csharp_1.dotnet.Bool, { parameters: [pKey], body: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.Remove( ${pKey})`), access: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Method(`${collectionInterfaceType.declaration}.Remove`, codegen_csharp_1.dotnet.Bool, { parameters: [pItem], body: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.Remove( ${pItem})`), access: codegen_csharp_1.Access.Explicit })); targetClass.add(new codegen_csharp_1.Method(`${dictionaryInterfaceType.declaration}.TryGetValue`, codegen_csharp_1.dotnet.Bool, { parameters: [pKey, pOutValue], body: (0, codegen_csharp_1.toExpression)(`${accessViaMember}.TryGetValue( ${pKey}, out ${pOutValue})`), access: codegen_csharp_1.Access.Explicit })); return dictionaryInterfaceType; } exports.implementIDictionary = implementIDictionary; //# sourceMappingURL=idictionary.js.map