public ColumnWidth(double value, ColumnWidthUnitType type) { if (double.IsNaN(value)) { throw new ArgumentException("NaN is not a valid value.", "value"); } if (double.IsInfinity(value)) { throw new ArgumentException("Infinity is not a valid value.", "value"); } if ((type != ColumnWidthUnitType.Pixel) && (type != ColumnWidthUnitType.Star)) { throw new InvalidEnumArgumentException("type", ( int )type, typeof(ColumnWidthUnitType)); } if (value < 0d) { throw new ArgumentException("Negative values are not valid.", "value"); } if ((Xceed.Utils.Math.DoubleUtil.AreClose(value, 0d)) && (type == ColumnWidthUnitType.Star)) { throw new ArgumentException("Zero star (0*) is not a valid value.", "value"); } m_unitValue = value; m_unitType = type; }
internal static ColumnWidth FromString(string stringValue, CultureInfo cultureInfo) { stringValue = stringValue.Trim().ToLowerInvariant(); double value = 0.0; ColumnWidthUnitType unit = ColumnWidthUnitType.Pixel; int stringValueLength = stringValue.Length; int unitStringLength = 0; double factorValue = 1.0; int index = 0; for (index = 0; index < ColumnWidthConverter.UnitStrings.Length; index++) { if (stringValue.EndsWith(ColumnWidthConverter.UnitStrings[index], StringComparison.Ordinal)) { unitStringLength = ColumnWidthConverter.UnitStrings[index].Length; unit = ( ColumnWidthUnitType )index; break; } } if (index >= ColumnWidthConverter.UnitStrings.Length) { // The unit type was not recognized so far. Search for pixel unit types. for (index = 0; index < ColumnWidthConverter.PixelUnitStrings.Length; index++) { if (stringValue.EndsWith(ColumnWidthConverter.PixelUnitStrings[index], StringComparison.Ordinal)) { unitStringLength = ColumnWidthConverter.PixelUnitStrings[index].Length; factorValue = ColumnWidthConverter.PixelUnitFactors[index]; break; } } } if ((stringValueLength == unitStringLength) && (unit == ColumnWidthUnitType.Star)) { // * was specified alone. Use the default value of 1. value = 1.0; } else { // Extract the numeric part of the string. string valuePartString = stringValue.Substring(0, stringValueLength - unitStringLength); value = Convert.ToDouble(valuePartString, cultureInfo) * factorValue; } return(new ColumnWidth(value, unit)); }
public ColumnWidth( double value, ColumnWidthUnitType type ) { if( double.IsNaN( value ) ) throw new ArgumentException( "NaN is not a valid value.", "value" ); if( double.IsInfinity( value ) ) throw new ArgumentException( "Infinity is not a valid value.", "value" ); if( ( type != ColumnWidthUnitType.Pixel ) && ( type != ColumnWidthUnitType.Star ) ) throw new InvalidEnumArgumentException( "type", ( int )type, typeof( ColumnWidthUnitType ) ); if( value < 0d ) throw new ArgumentException( "Negative values are not valid.", "value" ); if( ( Xceed.Utils.Math.DoubleUtil.AreClose( value, 0d ) ) && ( type == ColumnWidthUnitType.Star ) ) throw new ArgumentException( "Zero star (0*) is not a valid value.", "value" ); m_unitValue = value; m_unitType = type; }