Class ReglaRangoGrados
  Inherits ValidationRule
  Private m_tempMin As Double
  Private m_tempMax As Double

  Public Property TempMin() As Double
    Get
      Return m_tempMin
    End Get
    Set(value As Double)
      m_tempMin = value
    End Set
  End Property

  Public Property TempMax() As Double
    Get
      Return m_tempMax
    End Get
    Set(value As Double)
      m_tempMax = value
    End Set
  End Property

  Public Overrides Function Validate(value As Object,
  cultureInfo As System.Globalization.CultureInfo) _
  As ValidationResult
    Dim grados As Double
    If Not Double.TryParse(value.ToString(), grados) Then
      Return New ValidationResult(False,
        "La cadena de entrada no tiene el formato correcto.")
    End If

    If grados < m_tempMin OrElse grados > m_tempMax Then
      Return New ValidationResult(False,
        String.Format("Valor fuera del rango {0} a {1}",
                      m_tempMin, m_tempMax))
    End If

    Return ValidationResult.ValidResult
  End Function
End Class
