/// <summary> /// Converts a string representation of a quantity with a specific unit provider. /// </summary> /// <param name="input"> /// A string that contains the quantity to convert. /// </param> /// <param name="unitProvider"> /// The unit provider. If not specified, the default <see cref="UnitProvider" /> is used. /// </param> /// <returns> /// A <see cref="Radiation"/> that represents the quantity in <paramref name="input" />. /// </returns> public static Radiation Parse(string input, IUnitProvider unitProvider) { if (unitProvider == null) { unitProvider = UnitProvider.Default; } Radiation value; if (!unitProvider.TryParse(input, unitProvider.Culture, out value)) { throw new FormatException("Invalid format."); } return(value); }
/// <summary> /// Converts a string representation of a quantity in a specific culture-specific format with a specific unit provider. /// </summary> /// <param name="input"> /// A string that contains the quantity to convert. /// </param> /// <param name="provider"> /// An object that supplies culture-specific formatting information about <paramref name="input" />. If not specified, the culture of the default <see cref="UnitProvider" /> is used. /// </param> /// <param name="unitProvider"> /// The unit provider. If not specified, the default <see cref="UnitProvider" /> is used. /// </param> /// <returns> /// A <see cref="MassConcentrationInWater"/> that represents the quantity in <paramref name="input" />. /// </returns> public static MassConcentrationInWater Parse(string input, IFormatProvider provider, IUnitProvider unitProvider) { if (unitProvider == null) { unitProvider = provider as IUnitProvider ?? UnitProvider.Default; } MassConcentrationInWater value; if (!unitProvider.TryParse(input, provider, out value)) { throw new FormatException("Invalid format."); } return(value); }
/// <summary> /// Converts a string representation of a quantity in a specific culture-specific format with a specific unit provider. /// </summary> /// <param name="input"> /// A string that contains the quantity to convert. /// </param> /// <param name="provider"> /// An object that supplies culture-specific formatting information about <paramref name="input" />. If not specified, the culture of the default <see cref="UnitProvider" /> is used. /// </param> /// <param name="unitProvider"> /// The unit provider. If not specified, the default <see cref="UnitProvider" /> is used. /// </param> /// <returns> /// A <see cref="SecondMomentOfArea"/> that represents the quantity in <paramref name="input" />. /// </returns> public static SecondMomentOfArea Parse(string input, IFormatProvider provider = null, IUnitProvider unitProvider = null) { if (unitProvider == null) { unitProvider = provider as IUnitProvider ?? UnitProvider.Default; } SecondMomentOfArea value; if (!unitProvider.TryParse(input, provider, out value)) { throw new FormatException("Invalid format."); } return(value); }
/// <summary> /// Converts a string representation of a quantity in a specific culture-specific format with a specific unit provider. /// </summary> /// <param name="input"> /// A string that contains the quantity to convert. /// </param> /// <param name="provider"> /// An object that supplies culture-specific formatting information about <paramref name="input" />. If not specified, the culture of the default <see cref="UnitProvider" /> is used. /// </param> /// <param name="unitProvider"> /// The unit provider. If not specified, the default <see cref="UnitProvider" /> is used. /// </param> /// <returns> /// A <see cref="Illuminance"/> that represents the quantity in <paramref name="input" />. /// </returns> public static Illuminance Parse(string input, IFormatProvider provider, IUnitProvider unitProvider) { if (unitProvider == null) { unitProvider = provider as IUnitProvider ?? UnitProvider.Default; } Illuminance value; if (!unitProvider.TryParse(input, provider, out value)) { throw new FormatException("Invalid format."); } return(value); }
/// <summary> /// Converts a string representation of a quantity in a specific culture-specific format with a specific unit provider. /// </summary> /// <param name="input"> /// A string that contains the quantity to convert. /// </param> /// <param name="provider"> /// An object that supplies culture-specific formatting information about <paramref name="input" />. If not specified, the culture of the default <see cref="UnitProvider" /> is used. /// </param> /// <param name="unitProvider"> /// The unit provider. If not specified, the default <see cref="UnitProvider" /> is used. /// </param> /// <returns> /// A <see cref="SpecificHeatCapacity"/> that represents the quantity in <paramref name="input" />. /// </returns> public static SpecificHeatCapacity Parse(string input, IFormatProvider provider, IUnitProvider unitProvider) { if (unitProvider == null) { unitProvider = provider as IUnitProvider ?? UnitProvider.Default; } SpecificHeatCapacity value; if (!unitProvider.TryParse(input, provider, out value)) { throw new FormatException("Invalid format."); } return(value); }
/// <summary> /// Converts a string representation of a quantity in a specific culture-specific format with a specific unit provider. /// </summary> /// <param name="input"> /// A string that contains the quantity to convert. /// </param> /// <param name="provider"> /// An object that supplies culture-specific formatting information about <paramref name="input" />. If not specified, the culture of the default <see cref="UnitProvider" /> is used. /// </param> /// <param name="unitProvider"> /// The unit provider. If not specified, the default <see cref="UnitProvider" /> is used. /// </param> /// <returns> /// A <see cref="VelocitySquared"/> that represents the quantity in <paramref name="input" />. /// </returns> public static VelocitySquared Parse(string input, IFormatProvider provider = null, IUnitProvider unitProvider = null) { if (unitProvider == null) { unitProvider = provider as IUnitProvider ?? UnitProvider.Default; } VelocitySquared value; if (!unitProvider.TryParse(input, provider, out value)) { throw new FormatException("Invalid format."); } return(value); }
/// <summary> /// Converts a string representation of a quantity in a specific culture-specific format with a specific unit provider. /// </summary> /// <param name="input"> /// A string that contains the quantity to convert. /// </param> /// <param name="provider"> /// An object that supplies culture-specific formatting information about <paramref name="input" />. If not specified, the culture of the default <see cref="UnitProvider" /> is used. /// </param> /// <param name="unitProvider"> /// The unit provider. If not specified, the default <see cref="UnitProvider" /> is used. /// </param> /// <returns> /// A <see cref="RadiationAbsorbedDose"/> that represents the quantity in <paramref name="input" />. /// </returns> public static RadiationAbsorbedDose Parse(string input, IFormatProvider provider = null, IUnitProvider unitProvider = null) { if (unitProvider == null) { unitProvider = provider as IUnitProvider ?? UnitProvider.Default; } RadiationAbsorbedDose value; if (!unitProvider.TryParse(input, provider, out value)) { throw new FormatException("Invalid format."); } return(value); }
/// <summary> /// Converts a string representation of a quantity in a specific culture-specific format with a specific unit provider. /// </summary> /// <param name="input"> /// A string that contains the quantity to convert. /// </param> /// <param name="provider"> /// An object that supplies culture-specific formatting information about <paramref name="input" />. If not specified, the culture of the default <see cref="UnitProvider" /> is used. /// </param> /// <param name="unitProvider"> /// The unit provider. If not specified, the default <see cref="UnitProvider" /> is used. /// </param> /// <returns> /// A <see cref="TypographicLength"/> that represents the quantity in <paramref name="input" />. /// </returns> public static TypographicLength Parse(string input, IFormatProvider provider = null, IUnitProvider unitProvider = null) { if (unitProvider == null) { unitProvider = provider as IUnitProvider ?? UnitProvider.Default; } TypographicLength value; if (!unitProvider.TryParse(input, provider, out value)) { throw new FormatException("Invalid format."); } return(value); }
/// <summary> /// Converts a string representation of a quantity in a specific culture-specific format with a specific unit provider. /// </summary> /// <param name="input"> /// A string that contains the quantity to convert. /// </param> /// <param name="provider"> /// An object that supplies culture-specific formatting information about <paramref name="input" />. If not specified, the culture of the default <see cref="UnitProvider" /> is used. /// </param> /// <param name="unitProvider"> /// The unit provider. If not specified, the default <see cref="UnitProvider" /> is used. /// </param> /// <returns> /// A <see cref="VolumetricWaterContent"/> that represents the quantity in <paramref name="input" />. /// </returns> public static VolumetricWaterContent Parse(string input, IFormatProvider provider, IUnitProvider unitProvider) { if (unitProvider == null) { unitProvider = provider as IUnitProvider ?? UnitProvider.Default; } VolumetricWaterContent value; if (!unitProvider.TryParse(input, provider, out value)) { throw new FormatException("Invalid format."); } return(value); }
/// <summary> /// Converts a string representation of a quantity in a specific culture-specific format with a specific unit provider. /// </summary> /// <param name="input"> /// A string that contains the quantity to convert. /// </param> /// <param name="provider"> /// An object that supplies culture-specific formatting information about <paramref name="input" />. If not specified, the culture of the default <see cref="UnitProvider" /> is used. /// </param> /// <param name="unitProvider"> /// The unit provider. If not specified, the default <see cref="UnitProvider" /> is used. /// </param> /// <returns> /// A <see cref="MagneticFluxDensity"/> that represents the quantity in <paramref name="input" />. /// </returns> public static MagneticFluxDensity Parse(string input, IFormatProvider provider = null, IUnitProvider unitProvider = null) { if (unitProvider == null) { unitProvider = provider as IUnitProvider ?? UnitProvider.Default; } MagneticFluxDensity value; if (!unitProvider.TryParse(input, provider, out value)) { throw new FormatException("Invalid format."); } return(value); }
/// <summary> /// Parses the specified string. /// </summary> /// <param name="input"> /// The input string. /// </param> /// <param name="provider"> /// The provider. /// </param> /// <returns> /// The <see cref="MomentOfForce"/> . /// </returns> public static MomentOfForce Parse(string input, IUnitProvider provider = null) { if (provider == null) { provider = UnitProvider.Default; } double value; MomentOfForce unit; if (!provider.TryParse(input, out value, out unit)) { throw new FormatException(); } return(value * unit); }
public static Length Parse(string s, IUnitProvider provider = null) { if (provider == null) { provider = UnitProvider.Default; } double value; Length unit; if (!provider.TryParse(s, out value, out unit)) { throw new FormatException(); } return(value * unit); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var value = serializer.Deserialize <string>(reader); if (value == null) { return(null); } IQuantity q; if (unitProvider.TryParse(objectType, value, CultureInfo.InvariantCulture, out q)) { return(q); } throw new FormatException("Cannot parse " + value + " to " + objectType); }
/// <summary> /// Converts a string representation of a quantity with a specific unit provider. /// </summary> /// <param name="input"> /// A string that contains the quantity to convert. /// </param> /// <param name="unitProvider"> /// The unit provider. If not specified, the default <see cref="UnitProvider" /> is used. /// </param> /// <returns> /// A <see cref="Length"/> that represents the quantity in <paramref name="input" />. /// </returns> public static Length Parse(string input, IUnitProvider unitProvider) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (unitProvider == null) { unitProvider = UnitProvider.Default; } Length value; if (!unitProvider.TryParse(input, unitProvider.Culture, out value)) { throw new FormatException("Invalid format."); } return(value); }