// ------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ using System; using System.Collections.Generic; using System.Linq; using Microsoft.OData.Edm; using Microsoft.OpenApi.OData.Common; namespace Microsoft.OpenApi.OData.Edm { /// /// The key segment. /// public class ODataKeySegment : ODataSegment { /// /// Initializes a new instance of class. /// /// The entity type contains the keys. public ODataKeySegment(IEdmEntityType entityType) { EntityType = entityType ?? throw Error.ArgumentNull(nameof(entityType)); } /// public override IEdmEntityType EntityType { get; } /// public override string Name => throw new NotImplementedException(); /// public override string ToString() { IList keys = EntityType.Key().ToList(); if (keys.Count() == 1) { return "{" + keys.First().Name + "}"; } else { IList keyStrings = new List(); foreach (var keyProperty in keys) { keyStrings.Add(keyProperty.Name + "={" + keyProperty.Name + "}"); } return "{" + String.Join(",", keyStrings) + "}"; } } } }