Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs
===================================================================
diff -u -r3b1b80d82960d3bfa4906e06e37e73e4729eb3ad -r6c1eebbcec2bbe38093be8b1df1e683e50dfe3a5
--- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs (.../StructuresInputBaseProperties.cs) (revision 3b1b80d82960d3bfa4906e06e37e73e4729eb3ad)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs (.../StructuresInputBaseProperties.cs) (revision 6c1eebbcec2bbe38093be8b1df1e683e50dfe3a5)
@@ -24,6 +24,7 @@
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq.Expressions;
+using Core.Common.Base;
using Core.Common.Base.Data;
using Core.Common.Base.Geometry;
using Core.Common.Gui.Attributes;
@@ -168,6 +169,40 @@
///
protected abstract void AfterSettingStructure();
+ ///
+ /// Sets a probability value to one of the properties of a wrapped data object.
+ ///
+ /// The type of the wrapped data to set a probability value for.
+ /// The probability value to set.
+ /// The wrapped data to set a probability value for.
+ /// The action that sets the probability value to a specific property of the wrapped data.
+ /// Thrown when equals null.
+ /// Thrown when cannot be parsed into a double.
+ /// After correctly setting the to the wrapped data, observers will be notified.
+ protected static void SetProbabilityValue(string value,
+ T wrappedData,
+ Action setValueAction)
+ where T : IObservable
+ {
+ if (value == null)
+ {
+ throw new ArgumentNullException("value", Resources.FailureProbability_Value_cannot_be_null);
+ }
+ try
+ {
+ setValueAction(wrappedData, (RoundedDouble) double.Parse(value));
+ }
+ catch (OverflowException)
+ {
+ throw new ArgumentException(Resources.FailureProbability_Value_too_large);
+ }
+ catch (FormatException)
+ {
+ throw new ArgumentException(Resources.FailureProbability_Could_not_parse_string_to_double_value);
+ }
+ wrappedData.NotifyObservers();
+ }
+
private static string GetMemberName(Expression, object>> expression)
{
return TypeUtils.GetMemberName(expression);
@@ -411,23 +446,7 @@
}
set
{
- if (value == null)
- {
- throw new ArgumentNullException("value", Resources.FailureProbability_Value_cannot_be_null);
- }
- try
- {
- data.WrappedData.FailureProbabilityStructureWithErosion = (RoundedDouble) double.Parse(value);
- }
- catch (OverflowException)
- {
- throw new ArgumentException(Resources.FailureProbability_Value_too_large);
- }
- catch (FormatException)
- {
- throw new ArgumentException(Resources.FailureProbability_Could_not_parse_string_to_double_value);
- }
- data.WrappedData.NotifyObservers();
+ SetProbabilityValue(value, data.WrappedData, (wrappedData, parsedValue) => wrappedData.FailureProbabilityStructureWithErosion = parsedValue);
}
}