private static void ValidateDouble(String propertyName, Double propertyValue) { if (Double.IsInfinity(propertyValue) || Double.IsNaN(propertyValue)) { throw new VssPropertyValidationException("value", CommonResources.DoubleValueOutOfRange(propertyName, propertyValue)); } // SQL Server support: - 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308 if (propertyValue < s_minNegative || (propertyValue < 0 && propertyValue > s_maxNegative) || propertyValue > s_maxPositive || (propertyValue > 0 && propertyValue < s_minPositive)) { throw new VssPropertyValidationException("value", CommonResources.DoubleValueOutOfRange(propertyName, propertyValue)); } }
private static void ValidateDateTime(String propertyName, DateTime propertyValue) { // Let users get an out of range error for MinValue and MaxValue, not a DateTimeKind unspecified error. if (propertyValue != DateTime.MinValue && propertyValue != DateTime.MaxValue) { if (propertyValue.Kind == DateTimeKind.Unspecified) { throw new VssPropertyValidationException("value", CommonResources.DateTimeKindMustBeSpecified()); } // Make sure the property value is in Universal time. if (propertyValue.Kind != DateTimeKind.Utc) { propertyValue = propertyValue.ToUniversalTime(); } } CheckRange(propertyValue, s_minAllowedDateTime, s_maxAllowedDateTime, propertyName, "value"); }
public static void CheckPropertyLength(String propertyValue, Boolean allowNull, Int32 minLength, Int32 maxLength, String propertyName, Type containerType, String topLevelParamName) { Boolean valueIsInvalid = false; if (propertyValue == null) { if (!allowNull) { valueIsInvalid = true; } } else if ((propertyValue.Length < minLength) || (propertyValue.Length > maxLength)) { valueIsInvalid = true; } // throw exception if the value is invalid. if (valueIsInvalid) { // If the propertyValue is null, just print it like an empty string. if (propertyValue == null) { propertyValue = String.Empty; } if (allowNull) { // paramName comes second for ArgumentException. throw new ArgumentException(CommonResources.InvalidStringPropertyValueNullAllowed(propertyValue, propertyName, containerType.Name, minLength, maxLength), topLevelParamName); } else { throw new ArgumentException(CommonResources.InvalidStringPropertyValueNullForbidden(propertyValue, propertyName, containerType.Name, minLength, maxLength), topLevelParamName); } } }