blob: f0905826b2c5d857303d04d1c7ccc7c9f902657c [file] [log] [blame]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +01001/*******************************************************************************
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*******************************************************************************/
11using Newtonsoft.Json;
12using System.Collections.Generic;
13using System.Runtime.Serialization;
14
Constantin Ziesche08215502020-09-21 19:08:32 +020015namespace BaSyx.Models.Core.AssetAdministrationShell
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010016{
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}