| | 1 | | using System.Diagnostics.CodeAnalysis; |
| | 2 | | using System.Text.Json.Serialization; |
| | 3 | | using Spdx3.Exceptions; |
| | 4 | | using Spdx3.Model.Core.Classes; |
| | 5 | | using Spdx3.Model.SimpleLicensing.Classes; |
| | 6 | | using Spdx3.Serialization; |
| | 7 | | using Spdx3.Utility; |
| | 8 | |
|
| | 9 | | namespace Spdx3.Model.ExpandedLicensing.Classes; |
| | 10 | |
|
| | 11 | | /// <summary> |
| | 12 | | /// Portion of an AnyLicenseInfo representing a set of licensing information where only one of the elements applies. |
| | 13 | | /// See https://spdx.github.io/spdx-spec/v3.0.1/model/ExpandedLicensing/Classes/DisjunctiveLicenseSet/ |
| | 14 | | /// </summary> |
| | 15 | | public class DisjunctiveLicenseSet : AnyLicenseInfo |
| | 16 | | { |
| | 17 | | [JsonPropertyName("expandedlicensing_member")] |
| | 18 | | [JsonConverter(typeof(SpdxModelConverterFactory))] |
| 26 | 19 | | public IList<AnyLicenseInfo> Member { get; set; } = new List<AnyLicenseInfo>(); |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// No-arg constructor required for serialization/deserialization |
| | 23 | | /// </summary> |
| 0 | 24 | | protected internal DisjunctiveLicenseSet() |
| | 25 | | { |
| 0 | 26 | | } |
| | 27 | |
|
| | 28 | | [SetsRequiredMembers] |
| 5 | 29 | | public DisjunctiveLicenseSet(Catalog catalog, CreationInfo creationInfo, IList<AnyLicenseInfo> licenses) : base( |
| 5 | 30 | | catalog, creationInfo) |
| | 31 | | { |
| 5 | 32 | | if (licenses.Count < 2) |
| | 33 | | { |
| 0 | 34 | | throw new Spdx3Exception("DisjunctiveLicenseSets must have at least 2 licenses."); |
| | 35 | | } |
| | 36 | |
|
| 32 | 37 | | foreach (var anyLicenseInfo in licenses) |
| | 38 | | { |
| 11 | 39 | | Member.Add(anyLicenseInfo); |
| | 40 | | } |
| 5 | 41 | | } |
| | 42 | |
|
| | 43 | | public override void Validate() |
| | 44 | | { |
| 3 | 45 | | base.Validate(); |
| | 46 | |
|
| 3 | 47 | | if (Member.Count < 2) |
| | 48 | | { |
| 1 | 49 | | throw new Spdx3ValidationException("DisjunctiveLicenseSets must have at least 2 licenses."); |
| | 50 | | } |
| 2 | 51 | | } |
| | 52 | | } |