/// <summary> /// Converts provided literal from string representation to 32-bit integer. /// </summary> public static Number TryConvertToNumber(this TypeScript.Net.Types.ILiteralExpression literal) { Contract.Requires(literal != null); Contract.Requires(literal.Kind == TypeScript.Net.Types.SyntaxKind.NumericLiteral); return(LiteralConverter.TryConvertNumber(literal.Text)); }
internal static int AsNumber(this ILiteralExpression literalExpression, bool isNegative) { Contract.Requires(literalExpression != null); string text = isNegative ? I($"-{literalExpression.Text}") : literalExpression.Text; var result = LiteralConverter.TryConvertNumber(text); if (!result.IsValid) { Contract.Assert(false, I($"Conversion from literal expression to number should be successful. Text: {literalExpression.Text}")); } return(result.Value); }