Example #1
0
        /// <summary>
        /// Creates an accessor depending on the format.
        /// </summary>
        /// <param name="start">the zero-based index of the first byte of the accessor</param>
        /// <param name="length">the length of the accessor</param>
        /// <param name="format">the format of the accessor</param>
        /// <param name="encoding">the encoding of the accessed records</param>
        /// <returns>a new accessor with the correct parameters</returns>
        protected object GetAccessor(int start, int length, string format, Encoding encoding)
        {
            object result;

            switch (format)
            {
            case StringFormat:
            case SubstringFormat:
                result = new StringAccessor {
                    Encoding = encoding, Start = start, Length = length
                };
                break;

            case ZonedFormat:
                result = new ZonedAccessor {
                    Encoding = encoding, Length = length, Start = start
                };
                break;

            case PackedFormat:
                result = new PackedAccessor {
                    Encoding = encoding, Length = length, Start = start
                };
                break;

            case SignedBinaryFormat:
                result = new BinaryAccessor {
                    Encoding = encoding, Length = length, Start = start, Signed = true
                };
                break;

            case BinaryFormat:
                result = new BinaryAccessor {
                    Encoding = encoding, Length = length, Start = start, Signed = false
                };
                break;

            default:
                throw new ParsingException("Unknown format: " + format);
            }
            return(result);
        }
Example #2
0
 /// <summary>
 /// Creates an accessor depending on the format.
 /// </summary>
 /// <param name="start">the zero-based index of the first byte of the accessor</param>
 /// <param name="length">the length of the accessor</param>
 /// <param name="format">the format of the accessor</param>
 /// <param name="encoding">the encoding of the accessed records</param>
 /// <returns>a new accessor with the correct parameters</returns>
 protected object GetAccessor(int start, int length, string format, Encoding encoding)
 {
     object result;
     switch (format)
     {
         case StringFormat:
         case SubstringFormat:
             result = new StringAccessor { Encoding = encoding, Start = start, Length = length };
             break;
         case ZonedFormat:
             result = new ZonedAccessor { Encoding = encoding, Length = length, Start = start };
             break;
         case PackedFormat:
             result = new PackedAccessor { Encoding = encoding, Length = length, Start = start };
             break;
         case SignedBinaryFormat:
             result = new BinaryAccessor { Encoding = encoding, Length = length, Start = start, Signed = true };
             break;
         case BinaryFormat:
             result = new BinaryAccessor { Encoding = encoding, Length = length, Start = start, Signed = false };
             break;
         default:
             throw new ParsingException("Unknown format: " + format);
     }
     return result;
 }
Example #3
0
        /// <summary>
        /// Creates an accessor depending on the format.
        /// </summary>
        /// <param name="start">the zero-based index of the first byte of the accessor</param>
        /// <param name="length">the length of the accessor</param>
        /// <param name="format">the format of the accessor</param>
        /// <param name="encoding">the encoding of the accessed records</param>
        /// <returns>a new accessor with the correct parameters</returns>
        protected object GetAccessor(int start, int length, string format, Encoding encoding)
        {
            object result;

            switch (format)
            {
            case StringFormat:
            case SubstringFormat:
                result = new StringAccessor {
                    Encoding = encoding, Start = start, Length = length
                };
                break;

            case ZonedFormat:
                result = new ZonedAccessor {
                    Encoding = encoding, Length = length, Start = start
                };
                break;

            case PackedFormat:
                result = new PackedAccessor {
                    Encoding = encoding, Length = length, Start = start
                };
                break;

            case SignedBinaryFormat:
                result = new BinaryAccessor {
                    Encoding = encoding, Length = length, Start = start, Signed = true
                };
                break;

            case BinaryFormat:
                result = new BinaryAccessor {
                    Encoding = encoding, Length = length, Start = start, Signed = false
                };
                break;

            default:
                if (format != null && format.StartsWith(AsciiDecimalFormat))
                {
                    int precision = 0;
                    if (format.Length > 2)
                    {
                        precision = int.Parse(format.Substring(2));
                        result    = new AsciiAcessor {
                            Encoding = encoding, Length = length, Start = start, Precision = precision
                        };
                    }
                    else
                    {
                        throw new ParsingException("Unknown format: " + format);
                    }
                    break;
                }
                else
                {
                    throw new ParsingException("Unknown format: " + format);
                }
            }
            return(result);
        }