コード例 #1
0
        /// <summary>
        /// Converts the unit value of this instance to its equivalent string representation.
        /// </summary>
        /// <param name="symbolFormat">Specifies the symbol format to use when creating the string representation.</param>
        /// <returns>The string representation of the value of this instance.</returns>
        public string ToString(SymbolFormat symbolFormat)
        {
            var paddedFormat = UnitFormatCache <PressureUnit> .GetOrCreate(this, symbolFormat);

            using (var builder = StringBuilderPool.Borrow())
            {
                builder.Append(paddedFormat.PrePadding);
                builder.Append(paddedFormat.Format);
                builder.Append(paddedFormat.PostPadding);
                return(builder.ToString());
            }
        }
コード例 #2
0
        public string ToString(string format)
        {
            CurrentUnit unit;
            var paddedFormat = UnitFormatCache<CurrentUnit>.GetOrCreate(format, out unit);
            if (unit != this)
            {
                return format;
            }

            using (var builder = StringBuilderPool.Borrow())
            {
                builder.Append(paddedFormat.PrePadding);
                builder.Append(paddedFormat.Format);
                builder.Append(paddedFormat.PostPadding);
                return builder.ToString();
            }
        }
コード例 #3
0
        public string ToString(string format)
        {
            LuminousIntensityUnit unit;
            var paddedFormat = UnitFormatCache <LuminousIntensityUnit> .GetOrCreate(format, out unit);

            if (unit != this)
            {
                return(format);
            }

            using (var builder = StringBuilderPool.Borrow())
            {
                builder.Append(paddedFormat.PrePadding);
                builder.Append(paddedFormat.Format);
                builder.Append(paddedFormat.PostPadding);
                return(builder.ToString());
            }
        }
コード例 #4
0
        public string ToString(string format)
        {
            ElectricalConductanceUnit unit;
            var paddedFormat = UnitFormatCache <ElectricalConductanceUnit> .GetOrCreate(format, out unit);

            if (unit != this)
            {
                return(format);
            }

            using (var builder = StringBuilderPool.Borrow())
            {
                builder.Append(paddedFormat.PrePadding);
                builder.Append(paddedFormat.Format);
                builder.Append(paddedFormat.PostPadding);
                return(builder.ToString());
            }
        }
コード例 #5
0
        /// <summary>
        /// Converts the unit value of this instance to its equivalent string representation.
        /// </summary>
        /// <param name="format">The format to use when convereting</param>
        /// <returns>The string representation of the value of this instance.</returns>
        public string ToString(string format)
        {
            MagneticFieldStrengthUnit unit;
            var paddedFormat = UnitFormatCache <MagneticFieldStrengthUnit> .GetOrCreate(format, out unit);

            if (unit != this)
            {
                return(format);
            }

            using (var builder = StringBuilderPool.Borrow())
            {
                builder.Append(paddedFormat.PrePadding);
                builder.Append(paddedFormat.Format);
                builder.Append(paddedFormat.PostPadding);
                return(builder.ToString());
            }
        }
コード例 #6
0
        /// <summary>
        /// Converts the unit value of this instance to its equivalent string representation.
        /// </summary>
        /// <param name="format">The format to use when convereting</param>
        /// <returns>The string representation of the value of this instance.</returns>
        public string ToString(string format)
        {
            AngularAccelerationUnit unit;
            var paddedFormat = UnitFormatCache <AngularAccelerationUnit> .GetOrCreate(format, out unit);

            if (unit != this)
            {
                return(format);
            }

            using (var builder = StringBuilderPool.Borrow())
            {
                builder.Append(paddedFormat.PrePadding);
                builder.Append(paddedFormat.Format);
                builder.Append(paddedFormat.PostPadding);
                return(builder.ToString());
            }
        }
コード例 #7
0
        internal static bool TryParse <TUnit>(string format, ref int pos, out QuantityFormat <TUnit> result)
            where TUnit : struct, IUnit, IEquatable <TUnit>
        {
            if (string.IsNullOrWhiteSpace(format))
            {
                result = QuantityFormat <TUnit> .Default;
                return(true);
            }

            var valueFormat = DoubleFormatCache.GetOrCreate(format, ref pos);

            var symbolFormat = UnitFormatCache <TUnit> .GetOrCreate(format, ref pos, out TUnit unit);

            if (valueFormat.PostPadding == null &&
                symbolFormat.PrePadding == null)
            {
                // we want to keep the padding specified in the format
                // if both are null QuantityFormat infers padding.
                valueFormat = valueFormat.WithPostPadding(string.Empty);
            }

            if (valueFormat.IsUnknown)
            {
                if (symbolFormat.IsUnknown)
                {
                    result = QuantityFormat <TUnit> .CreateUnknown(format, Unit <TUnit> .Default);

                    return(false);
                }

                if (valueFormat.Format.StartsWith(symbolFormat.Format))
                {
                    valueFormat = valueFormat.WithFormat(null);
                }
            }

            result = QuantityFormat <TUnit> .Create(valueFormat, symbolFormat, unit);

            return(!(valueFormat.IsUnknown || symbolFormat.IsUnknown));
        }