Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingDistributionPropertiesBase.cs
===================================================================
diff -u -rf8998df0ea8c1228216bbb00ed9178058af4af67 -r2abaaf908070732e84673348cca9df2a600b8450
--- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingDistributionPropertiesBase.cs (.../ConfirmingDistributionPropertiesBase.cs) (revision f8998df0ea8c1228216bbb00ed9178058af4af67)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingDistributionPropertiesBase.cs (.../ConfirmingDistributionPropertiesBase.cs) (revision 2abaaf908070732e84673348cca9df2a600b8450)
@@ -26,7 +26,6 @@
using Core.Common.Gui.Attributes;
using Core.Common.Gui.PropertyBag;
using Core.Common.Utils.Attributes;
-using Core.Common.Utils.Reflection;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.Probabilistics;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
@@ -41,8 +40,8 @@
where TCalculationInput : ICalculationInput
where TCalculation : ICalculation
{
- private readonly string meanPropertyName;
- private readonly string standardDeviationPropertyName;
+ private const string meanPropertyName = nameof(Mean);
+ private const string standardDeviationPropertyName = nameof(StandardDeviation);
private readonly bool isMeanReadOnly;
private readonly bool isStandardDeviationReadOnly;
private readonly TCalculationInput calculationInput;
@@ -60,10 +59,10 @@
/// Thrown when is null
/// or when any number of properties in this class is editable and any other parameter is null.
protected ConfirmingDistributionPropertiesBase(DistributionPropertiesReadOnly propertiesReadOnly,
- TDistribution data,
- TCalculation calculation,
- TCalculationInput calculationInput,
- ICalculationInputPropertyChangeHandler handler)
+ TDistribution data,
+ TCalculation calculation,
+ TCalculationInput calculationInput,
+ ICalculationInputPropertyChangeHandler handler)
{
if (data == null)
{
@@ -86,9 +85,6 @@
}
Data = data;
- meanPropertyName = TypeUtils.GetMemberName>(dpb => dpb.Mean);
- standardDeviationPropertyName = TypeUtils.GetMemberName>(dpb => dpb.StandardDeviation);
-
isMeanReadOnly = propertiesReadOnly.HasFlag(DistributionPropertiesReadOnly.Mean);
isStandardDeviationReadOnly = propertiesReadOnly.HasFlag(DistributionPropertiesReadOnly.StandardDeviation);
@@ -115,11 +111,10 @@
{
if (isMeanReadOnly)
{
- throw new ArgumentException("Mean is set to be read-only.");
+ throw new InvalidOperationException("Mean is set to be read-only.");
}
- IEnumerable affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(calculationInput, calculation, value, (input, d) => data.Mean = d);
- NotifyAffectedObjects(affectedObjects);
+ ChangePropertyAndNotify((input, newValue) => data.Mean = newValue, value);
}
}
@@ -136,11 +131,10 @@
{
if (isStandardDeviationReadOnly)
{
- throw new ArgumentException("StandardDeviation is set to be read-only.");
+ throw new InvalidOperationException("StandardDeviation is set to be read-only.");
}
- IEnumerable affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(calculationInput, calculation, value, (input, d) => data.StandardDeviation = d);
- NotifyAffectedObjects(affectedObjects);
+ ChangePropertyAndNotify((input, newValue) => data.StandardDeviation = newValue, value);
}
}
@@ -158,9 +152,19 @@
return $"{Mean} ({RingtoetsCommonFormsResources.NormalDistribution_StandardDeviation_DisplayName} = {StandardDeviation})";
}
+ private void ChangePropertyAndNotify(SetCalculationInputPropertyValueDelegate setPropertyValue,
+ RoundedDouble value)
+ {
+ IEnumerable affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(calculationInput,
+ calculation,
+ value,
+ setPropertyValue);
+ NotifyAffectedObjects(affectedObjects);
+ }
+
private static void NotifyAffectedObjects(IEnumerable affectedObjects)
{
- foreach (var affectedObject in affectedObjects)
+ foreach (IObservable affectedObject in affectedObjects)
{
affectedObject.NotifyObservers();
}