예제 #1
0
파일: Formatter.cs 프로젝트: Piirtaa/Arith
        /// <summary>
        /// pads numeric format with spaces.  if no format function provided, format
        /// defaults to Simple
        /// </summary>
        /// <param name="thisNumeric"></param>
        /// <param name="maxWholeNumberLength"></param>
        /// <param name="maxDecimalLength"></param>
        /// <returns></returns>
        public static string DecimalAlignFormat(this INumeric thisNumeric,
      Numeric maxWholeNumberLength,
            Numeric maxDecimalLength,
            Func<INumeric, string> format = null
        )
        {
            if (thisNumeric == null)
                throw new ArgumentNullException("thisNumeric");

            Func<INumeric, string> actualFormat = (x) =>
            {
                return thisNumeric.GetSimpleFormat();
            };

            if (format != null)
                actualFormat = format;

            string val = actualFormat(thisNumeric);

            Numeric eachWholeNumberLength = null;
            Numeric eachDecimalLength = null;
            thisNumeric.GetNumericLengths(out eachWholeNumberLength, out eachDecimalLength);

            var postPadLength = maxWholeNumberLength.Clone().HasAddition();
            postPadLength.Subtract(eachWholeNumberLength);

            var prePadLength = maxDecimalLength.Clone().HasAddition();
            prePadLength.Subtract(eachDecimalLength);

            postPadLength.PerformThisManyTimes(x =>
            {
                val = " " + val;
            });

            prePadLength.PerformThisManyTimes(x =>
            {
                val = val + " ";
            });
            return val;
        }