/// <summary>
        /// Gets a fixed-length line builder.
        /// </summary>
        /// <param name="descriptor">The layout a builder is for.</param>
        /// <returns>A new fixed-length line builder.</returns>
        public IFixedLengthLineBuilder GetBuilder(IFixedLengthLayoutDescriptor descriptor)
        {
            if (!_lineBuilders.TryGetValue(descriptor.TargetType, out var builder))
            {
                builder = new FixedLengthLineBuilder(descriptor);
                _lineBuilders[descriptor.TargetType] = builder;
            }

            return(builder);
        }
        public FixedLengthErrorHandlingTests()
        {
            layout = A.Fake <IFixedLengthLayoutDescriptor>();
            A.CallTo(() => layout.TargetType).Returns(typeof(Record));
            A.CallTo(() => layout.InstanceFactory).Returns(() => new Record());

            lineParserFactory = A.Fake <IFixedLengthLineParserFactory>();
            A.CallTo(() => lineParserFactory.GetParser(A <IFixedLengthLayoutDescriptor> .Ignored))
            .Returns(new FakeLineParser());
        }
        /// <summary>
        /// Gets the parser.
        /// </summary>
        /// <param name="descriptor">The descriptor.</param>
        /// <returns>IFixedLengthLineParser.</returns>
        public IFixedLengthLineParser GetParser(IFixedLengthLayoutDescriptor descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (!_parsers.TryGetValue(descriptor.TargetType, out var parser))
            {
                parser = descriptor.TargetType != null && _parserRegistry.TryGetValue(descriptor.TargetType, out var parserType)
                    ? (IFixedLengthLineParser)ReflectionHelper.CreateInstance(parserType, true, descriptor)
                    : new FixedLengthLineParser(descriptor);

                _parsers[descriptor.TargetType] = parser;
            }

            return(parser);
        }
 /// <summary>
 /// Initializes a new instance of <see cref="FixedLengthImmutableLayoutDescriptor"/>.
 /// </summary>
 /// <param name="existing">The descriptor to copy.</param>
 public FixedLengthImmutableLayoutDescriptor(IFixedLengthLayoutDescriptor existing)
     : base(existing)
 {
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of <see cref="FixedLengthLineBuilder"/>.
 /// </summary>
 /// <param name="layout">Describes how a type maps to a file record.</param>
 public FixedLengthLineBuilder(IFixedLengthLayoutDescriptor layout)
     : base(layout)
 {
     _lineBuilder = new StringBuilder(layout.Fields.Sum(f => f.Length));
 }