Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2020 Robert Bosch GmbH |
| 3 | * Author: Constantin Ziesche (constantin.ziesche@bosch.com) |
| 4 | * |
| 5 | * This program and the accompanying materials are made available under the |
| 6 | * terms of the Eclipse Public License 2.0 which is available at |
| 7 | * http://www.eclipse.org/legal/epl-2.0 |
| 8 | * |
| 9 | * SPDX-License-Identifier: EPL-2.0 |
| 10 | *******************************************************************************/ |
| 11 | using Newtonsoft.Json; |
| 12 | using System.Collections.Generic; |
| 13 | using System.Runtime.Serialization; |
| 14 | |
Constantin Ziesche | 0821550 | 2020-09-21 19:08:32 +0200 | [diff] [blame^] | 15 | namespace BaSyx.Models.Core.AssetAdministrationShell |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 16 | { |
| 17 | [DataContract] |
| 18 | public class LangStringSet : List<LangString> |
| 19 | { |
| 20 | [JsonConstructor] |
| 21 | public LangStringSet(IEnumerable<LangString> langStrings) : base(langStrings) { } |
| 22 | |
| 23 | public LangStringSet() { } |
| 24 | |
| 25 | public string this[string language] => this.Find(e => e.Language == language)?.Text; |
| 26 | |
| 27 | public LangStringSet AddLangString(string language, string text) => AddLangString(new LangString(language, text)); |
| 28 | |
| 29 | public LangStringSet AddLangString(LangString langString) |
| 30 | { |
| 31 | int index = this.FindIndex(c => c.Language == langString.Language); |
| 32 | if (index == -1) |
| 33 | Add(langString); |
| 34 | else |
| 35 | this[index] = langString; |
| 36 | |
| 37 | return this; |
| 38 | } |
| 39 | |
| 40 | public override string ToString() |
| 41 | { |
| 42 | return string.Join(";", this); |
| 43 | } |
| 44 | |
| 45 | } |
| 46 | } |