/// <summary> /// Get an integer attribute value and displays an error for an illegal integer value. /// </summary> /// <param name="sourceLineNumbers">Source line information about the owner element.</param> /// <param name="attribute">The attribute containing the value to get.</param> /// <param name="minimum">The minimum legal value.</param> /// <param name="maximum">The maximum legal value.</param> /// <param name="messageHandler">A delegate that receives error messages.</param> /// <returns>The attribute's integer value or a special value if an error occurred during conversion.</returns> public static int GetAttributeIntegerValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute, int minimum, int maximum) { Debug.Assert(minimum > CompilerConstants.IntegerNotSet && minimum > CompilerConstants.IllegalInteger, "The legal values for this attribute collide with at least one sentinel used during parsing."); string value = Common.GetAttributeValue(messaging, sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); int integer = CompilerConstants.IllegalInteger; if (0 < value.Length) { if (Int32.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture.NumberFormat, out integer)) { if (CompilerConstants.IntegerNotSet == integer || CompilerConstants.IllegalInteger == integer) { messaging.Write(ErrorMessages.IntegralValueSentinelCollision(sourceLineNumbers, integer)); } else if (minimum > integer || maximum < integer) { messaging.Write(ErrorMessages.IntegralValueOutOfRange(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, integer, minimum, maximum)); integer = CompilerConstants.IllegalInteger; } } else { messaging.Write(ErrorMessages.IllegalIntegerValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } } return(integer); }
/// <summary> /// Get an identifier attribute value and displays an error for an illegal identifier value. /// </summary> /// <param name="sourceLineNumbers">Source line information about the owner element.</param> /// <param name="attribute">The attribute containing the value to get.</param> /// <param name="messageHandler">A delegate that receives error messages.</param> /// <returns>The attribute's identifier value or a special value if an error occurred.</returns> internal static string GetAttributeIdentifierValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute) { string value = Common.GetAttributeValue(messaging, sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); if (Common.IsIdentifier(value)) { if (72 < value.Length) { messaging.Write(WarningMessages.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } return(value); } else { if (value.StartsWith("[", StringComparison.Ordinal) && value.EndsWith("]", StringComparison.Ordinal)) { messaging.Write(ErrorMessages.IllegalIdentifierLooksLikeFormatted(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } else { messaging.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } return(String.Empty); } }
/// <summary> /// Gets a yes/no value and displays an error for an illegal yes/no value. /// </summary> /// <param name="sourceLineNumbers">Source line information about the owner element.</param> /// <param name="attribute">The attribute containing the value to get.</param> /// <param name="messageHandler">A delegate that receives error messages.</param> /// <returns>The attribute's YesNoType value.</returns> internal static YesNoType GetAttributeYesNoValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute) { string value = Common.GetAttributeValue(messaging, sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); YesNoType yesNo = YesNoType.IllegalValue; if ("yes".Equals(value) || "true".Equals(value)) { yesNo = YesNoType.Yes; } else if ("no".Equals(value) || "false".Equals(value)) { yesNo = YesNoType.No; } else { messaging.Write(ErrorMessages.IllegalYesNoValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } return(yesNo); }