I have a model consisting of specifications. Each property is a string that I'm converting to an integer for comparison. In the case of there being a null comparison it defaults to false where I want it to be ignored or default to true. Each of the properties needs to be compared to each other and the solution I've come up with is messy. I'm looking for a more readable/reusable solution.
The exception is getting pushed to a grid for the user to see.
/// <summary>
/// Lower Entry Limit of the spec
/// </summary>
public string LEL
{
get { return _LEL; }
set
{
//This is what I've come up with
if(value != null)
{
if (_LRL != null)
{
if (Utilities.ConvertSafe.ToInt32(value) > (Utilities.ConvertSafe.ToInt32(_LRL))) throw new Exception("LEL not correct");
}
if (_LWL != null)
{
if (Utilities.ConvertSafe.ToInt32(value) > (Utilities.ConvertSafe.ToInt32(_LWL))) throw new Exception("LEL not correct");
}
_LEL = value; NotifyPropertyChanged(this, "LEL");
//-------------------------------------
//Want something more like this
if (Utilities.ConvertSafe.ToInt32(value) < (Utilities.ConvertSafe.ToInt32(_LRL)) //If is _LRL is null ignore this comparison
&& Utilities.ConvertSafe.ToInt32(value) < Utilities.ConvertSafe.ToInt32(_LWL)
&& Utilities.ConvertSafe.ToInt32(value) < Utilities.ConvertSafe.ToInt32(_LUL)
&& Utilities.ConvertSafe.ToInt32(value) < Utilities.ConvertSafe.ToInt32(_Target)
&& Utilities.ConvertSafe.ToInt32(value) < Utilities.ConvertSafe.ToInt32(_UUL)
&& Utilities.ConvertSafe.ToInt32(value) < Utilities.ConvertSafe.ToInt32(_UWL)
&& Utilities.ConvertSafe.ToInt32(value) < Utilities.ConvertSafe.ToInt32(_URL)
&& Utilities.ConvertSafe.ToInt32(value) < Utilities.ConvertSafe.ToInt32(_UEL)
)
{
_LEL = value; NotifyPropertyChanged(this, "LEL");
}
else { throw new Exception("LEL not correct"); }
}
}
}