231 lines
8.3 KiB
C#
231 lines
8.3 KiB
C#
|
|
/*
|
|||
|
|
RangeRestrictedDoubleProperty.cs
|
|||
|
|
|
|||
|
|
Copyright <EFBFBD> 2008
|
|||
|
|
Diversified Technical Systems, Inc.
|
|||
|
|
All Rights Reserved
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Diagnostics;
|
|||
|
|
using System.Text;
|
|||
|
|
using DTS.Common.Utilities;
|
|||
|
|
|
|||
|
|
namespace DTS.Common.Utilities.DotNetProgrammingConstructs
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// A class to implement self-checking, on-error-auto-syntax-building
|
|||
|
|
/// range-restricted int properties.
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class RangeRestrictedDoubleProperty : Property<double>
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Determine whether or not the specified value is valid for this property.
|
|||
|
|
/// </summary>
|
|||
|
|
///
|
|||
|
|
/// <param name="value">
|
|||
|
|
/// The <see cref="double"/> value to be validity checked.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
/// <returns>
|
|||
|
|
/// <see cref="bool"/> true if the value is valid; false otherwise.
|
|||
|
|
/// </returns>
|
|||
|
|
///
|
|||
|
|
public override bool IsValidValue(double value)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
return value >= MinimumValue && value <= MaximumValue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new Exception(
|
|||
|
|
string.Format(Properties.Resources.RangeRestrictedDoubleProperty_IsValidValue_UnableToDetermineValidityString, value.ToString()),
|
|||
|
|
ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Generate a user-readable explanation as to why the specified value is
|
|||
|
|
/// not valid for this property.
|
|||
|
|
/// </summary>
|
|||
|
|
///
|
|||
|
|
/// <param name="value">
|
|||
|
|
/// The <see cref="int"/> value to be described.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
/// <returns>
|
|||
|
|
/// A <see cref="string"/> description explaining why the specified value
|
|||
|
|
/// is not valid for this property.
|
|||
|
|
/// </returns>
|
|||
|
|
///
|
|||
|
|
public string GetInvalidValueDescription(int value)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (value < MinimumValue)
|
|||
|
|
return string.Format(Properties.Resources.RangeRestrictedDoubleProperty_GetInvalidValueDescription_MinimumDescriptionString, value.ToString(), MinimumValue.ToString());
|
|||
|
|
else if (value > MaximumValue)
|
|||
|
|
return string.Format(Properties.Resources.RangeRestrictedDoubleProperty_GetInvalidValueDescription_MaximumDescriptionString, value.ToString(), MaximumValue.ToString());
|
|||
|
|
else
|
|||
|
|
return string.Format(Properties.Resources.RangeRestrictedDoubleProperty_GetInvalidValueDescription_ValidValueDescriptionString, value.ToString());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new Exception(
|
|||
|
|
string.Format(Properties.Resources.RangeRestrictedDoubleProperty_GetInvalidValueDescription_GetDescriptionFailedString, value.ToString()),
|
|||
|
|
ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// The minimum <see cref="double"/> value permitted in this property.
|
|||
|
|
/// </summary>
|
|||
|
|
public double MinimumValue
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
return _MinimumValue.Value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new Exception(Properties.Resources.RangeRestrictedDoubleProperty_MinimumValue_GetValueFailedString, ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
try { _MinimumValue.Value = value; }
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new Exception(Properties.Resources.RangeRestrictedDoubleProperty_MinimumValue_SetValueFailedString, ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private readonly Property<double> _MinimumValue = new Property<double>(0, false);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// The maximum <see cref="double"/> value permitted in this property.
|
|||
|
|
/// </summary>
|
|||
|
|
public double MaximumValue
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
return _MaximumValue.Value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new Exception(Properties.Resources.RangeRestrictedDoubleProperty_MaximumValue_GetValueFailedString, ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
try { _MaximumValue.Value = value; }
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new Exception(Properties.Resources.RangeRestrictedDoubleProperty_MaximumValue_SetValueFailedString, ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private readonly Property<double> _MaximumValue = new Property<double>(0, false);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Initialize an instance of a range-restricted integer property.
|
|||
|
|
/// </summary>
|
|||
|
|
///
|
|||
|
|
/// <param name="minimumValue">
|
|||
|
|
/// The minimum <see cref="int"/> value permitted in this property.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
/// <param name="maximumValue">
|
|||
|
|
/// The maximum <see cref="int"/> value permitted in this property.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
/// <param name="initialValue">
|
|||
|
|
/// The initial <see cref="int"/> value of this property.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
/// <param name="isInitialized">
|
|||
|
|
/// <see cref="bool"/> true if this property is to be considered
|
|||
|
|
/// initialized after construction, false otherwise.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
public RangeRestrictedDoubleProperty(double minimumValue,
|
|||
|
|
double maximumValue,
|
|||
|
|
double initialValue,
|
|||
|
|
bool isInitialized)
|
|||
|
|
: base(initialValue, isInitialized)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (minimumValue > maximumValue)
|
|||
|
|
throw new InvalidRangeException(
|
|||
|
|
string.Format(
|
|||
|
|
Properties.Resources.RangeRestrictedDoubleProperty_MinMustBeLessThanMaxString, minimumValue.ToString(), maximumValue.ToString()));
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
MinimumValue = minimumValue;
|
|||
|
|
MaximumValue = maximumValue;
|
|||
|
|
if (!IsValidValue(initialValue))
|
|||
|
|
throw new InvalidValueException(GetInvalidValueDescription(initialValue));
|
|||
|
|
else return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new ConstructionException(
|
|||
|
|
string.Format(Properties.Resources.Generic_EncounteredProblemConstructingClassString, GetType().FullName),
|
|||
|
|
ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Initialize an instance of a range-restricted integer property.
|
|||
|
|
/// </summary>
|
|||
|
|
///
|
|||
|
|
/// <param name="minimumValue">
|
|||
|
|
/// The minimum <see cref="double"/> value permitted in this property.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
/// <param name="maximumValue">
|
|||
|
|
/// The maximum <see cref="double"/> value permitted in this property.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
public RangeRestrictedDoubleProperty(double minimumValue, double maximumValue)
|
|||
|
|
: base(0, false)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (minimumValue > maximumValue)
|
|||
|
|
throw new InvalidRangeException(
|
|||
|
|
string.Format(
|
|||
|
|
Properties.Resources.RangeRestrictedDoubleProperty_MinMustBeLessThanMaxString, minimumValue.ToString(), maximumValue.ToString()));
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
MinimumValue = minimumValue;
|
|||
|
|
MaximumValue = maximumValue;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new ConstructionException(
|
|||
|
|
string.Format(
|
|||
|
|
Properties.Resources.Generic_EncounteredProblemConstructingClassString, GetType().FullName),
|
|||
|
|
ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|