Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Data/GrassCoverErosionOutwardsFailureMechanismExtensions.cs =================================================================== diff -u -r871a2151d7a49d6f50699b6dea82c3e20ba6e409 -rf7d73da8b5830eb8d37f50e94eb85e22f3e6b1c3 --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Data/GrassCoverErosionOutwardsFailureMechanismExtensions.cs (.../GrassCoverErosionOutwardsFailureMechanismExtensions.cs) (revision 871a2151d7a49d6f50699b6dea82c3e20ba6e409) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Data/GrassCoverErosionOutwardsFailureMechanismExtensions.cs (.../GrassCoverErosionOutwardsFailureMechanismExtensions.cs) (revision f7d73da8b5830eb8d37f50e94eb85e22f3e6b1c3) @@ -21,8 +21,11 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; -using Core.Common.Util.Extensions; +using Core.Common.Base.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.Hydraulics; namespace Ringtoets.GrassCoverErosionOutwards.Data @@ -59,5 +62,66 @@ failureMechanism.HydraulicBoundaryLocations.AddRange(hydraulicBoundaryLocations); } + + /// + /// Gets the normative assessment level for a . + /// + /// The assessment section to get the normative assessment level from. + /// The failure mechanism to get the normative assessment level from. + /// The hydraulic boundary location to get the normative assessment level for. + /// The normative assessment level or when: + /// + /// is null; + /// is not part of ; + /// is not part of ; + /// contains no corresponding calculation output. + /// + /// + /// Thrown when + /// or is null. + /// Thrown when + /// contains an invalid value of . + /// Thrown when + /// contains a valid value of , but unsupported. + public static RoundedDouble GetNormativeAssessmentLevel(this GrassCoverErosionOutwardsFailureMechanism failureMechanism, + IAssessmentSection assessmentSection, + HydraulicBoundaryLocation hydraulicBoundaryLocation) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + NormType normType = assessmentSection.FailureMechanismContribution.NormativeNorm; + + if (!Enum.IsDefined(typeof(NormType), normType)) + { + throw new InvalidEnumArgumentException(nameof(normType), + (int)normType, + typeof(NormType)); + } + + IEnumerable calculations; + + switch (normType) + { + case NormType.Signaling: + calculations = failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm; + break; + case NormType.LowerLimit: + calculations = assessmentSection.WaterLevelCalculationsForLowerLimitNorm; + break; + default: + throw new NotSupportedException(); + } + + return calculations.FirstOrDefault(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation))?.Output?.Result + ?? RoundedDouble.NaN; + } } } \ No newline at end of file