using System;
using System.Globalization;
namespace Ubisoft
{
///
/// Utility class for dealing with short type.
///
public static class HtShort
{
public static readonly IFormatProvider DefaultFormatProvider = HtTypes.DefaultFormatProvider;
///
/// Converts the string representation of a number to its 16-bit signed integer equivalent. A return value indicates whether the conversion succeeded.
///
/// This method uses NumberStyles.Integer and CultureInfo.InvariantCulture.
/// Use this method when the string to convert comes from Content or persistence.
///
/// A string containing a number to convert.
/// When this method returns, contains the 16-bit signed integer value equivalent of the number contained in s,
/// if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null or Empty,
/// is not of the correct format, or represents a number less than MinValue or greater than MaxValue.
/// This parameter is passed uninitialized; any value originally supplied in result will be overwritten.
/// true if s was converted successfully; otherwise, false
public static bool TryParse(string s, out short result)
{
return TryParse(s, DefaultFormatProvider, out result);
}
///
/// Converts the string representation of a number to its 16-bit signed integer equivalent. A return value indicates whether the conversion succeeded.
///
/// This method uses NumberStyles.Integer.
///
/// A string containing a number to convert.
/// An object that supplies culture-specific formatting information about s.
/// When this method returns, contains the 16-bit signed integer value equivalent of the number contained in s,
/// if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null or Empty,
/// is not of the correct format, or represents a number less than MinValue or greater than MaxValue.
/// This parameter is passed uninitialized; any value originally supplied in result will be overwritten.
/// true if s was converted successfully; otherwise, false
public static bool TryParse(string s, IFormatProvider formatProvider, out short result)
{
return short.TryParse(s, NumberStyles.Integer, formatProvider, out result);
}
///
/// Converts the string representation of a number to its 16-bit signed integer equivalent.
///
/// This method uses NumberStyles.Integer and CultureInfo.InvariantCulture.
/// Use this method when the string to convert comes from Content or persistence.
///
/// A string containing a number to convert.
/// A 16-bit signed integer equivalent to the number specified in s
/// or
/// ArgumentNullException if s is null.
/// or
/// FormatException if s is not in a format compliant with CultureInfo.InvariantCulture.
/// or
/// OverflowException if s represents a number less than MinValue or greater than MaxValue or s includes non-zero, fractional digits.
///
public static short Parse(string s)
{
return Parse(s, DefaultFormatProvider);
}
///
/// Converts the string representation of a number to its 16-bit signed integer equivalent.
///
/// This method uses NumberStyles.Integer.
/// Use this method when the string to convert comes from Content or persistence.
///
/// A string containing a number to convert.
/// An object that supplies culture-specific formatting information about s.
/// A 16-bit signed integer equivalent to the number specified in s
/// or
/// ArgumentNullException if s is null.
/// or
/// FormatException if s is not in a format compliant with CultureInfo.InvariantCulture.
/// or
/// OverflowException if s represents a number less than MinValue or greater than MaxValue or s includes non-zero, fractional digits.
///
public static short Parse(string s, IFormatProvider formatProvider)
{
return short.Parse(s, NumberStyles.Integer, formatProvider);
}
///
/// Converts the numeric value passed in to its equivalent string representation using CultureInfo.InvariantCulture.
///
/// Use this method when you need the string returned to be independent from user's culture, typically when storing persistence, which
/// will be loaded by using HtShort.Parse() or HtShort.TryParse() methods.
///
/// A 16-bit signed integer.
/// The string representation of the value.
public static string ToString(short value)
{
return value.ToString(DefaultFormatProvider);
}
}
}