Пример #1
0
 public static string Format(this IsoType isoType,
                             long value,
                             int length)
 {
     if (isoType == IsoType.NUMERIC)
     {
         var x = value.ToString().PadLeft(length,
                                          '0');
         if (x.Length > length)
         {
             throw new ArgumentException("Numeric value is larger than intended length: " + value + " LEN " +
                                         length);
         }
         return(x);
     }
     if (isoType == IsoType.ALPHA || isoType == IsoType.LLVAR || isoType == IsoType.LLLVAR ||
         isoType == IsoType.LLLLVAR)
     {
         return(isoType.Format(Convert.ToString(value),
                               length));
     }
     if (isoType == IsoType.AMOUNT)
     {
         return(value.ToString("0000000000") + "00");
     }
     if (isoType == IsoType.BINARY || isoType == IsoType.LLBIN || isoType == IsoType.LLLBIN ||
         isoType == IsoType.LLLLBIN)
     {
         //TODO
     }
     throw new ArgumentException("Cannot format number as " + isoType);
 }
Пример #2
0
        public static string Format(this IsoType isoType,
                                    decimal value,
                                    int length)
        {
            if (isoType == IsoType.AMOUNT)
            {
                var x      = value.ToString("0000000000.00").ToCharArray();
                var digits = new char[12];
                Array.Copy(x,
                           digits,
                           10);
                Array.Copy(x,
                           11,
                           digits,
                           10,
                           2);
                return(new string(digits));
            }

            if (isoType == IsoType.NUMERIC)
            {
                return(isoType.Format(Convert.ToInt64(value),
                                      length));
            }
            if (isoType == IsoType.ALPHA || isoType == IsoType.LLVAR || isoType == IsoType.LLLVAR ||
                isoType == IsoType.LLLLVAR)
            {
                return(isoType.Format(Convert.ToString(value),
                                      length));
            }
            if (isoType == IsoType.BINARY || isoType == IsoType.LLBIN || isoType == IsoType.LLLBIN ||
                isoType == IsoType.LLLLBIN)
            {
                //TODO
            }
            throw new ArgumentException("Cannot format decimal as " + isoType);
        }