Exemple #1
0
        public void InitializeFixeds()
        {
            headerCheckGetter = GetHeaderCheckGetterFixeds();

            var properties    = recordType.GetFixedsProperties();
            var fixedsGetters = properties.GetFixedGetters().ToArray();

            contentGetter = (string line) => line.GetContents(
                getters: fixedsGetters,
                trimValues: trimValues);

            var index = 0;

            foreach (var property in properties)
            {
                CreateFieldSetterSingle(
                    property: property,
                    fieldIndex: index++);
            }

            var childProperties = recordType.GetChildProperties();

            foreach (var childProperty in childProperties)
            {
                var childFactory = GetChildFactory(childProperty);
                childFactory.InitializeFixeds();

                HeaderPatterns.UnionWith(childFactory.HeaderPatterns);
            }
        }
Exemple #2
0
        public void InitializeDelimiteds()
        {
            headerCheckGetter = GetHeaderCheckGetterDelimiteds();

            var properties = recordType.GetDelimitedsProperties();

            contentGetter = (line) => line.GetContents(
                separator: valueSeparators,
                trimValues: trimValues);

            foreach (var property in properties)
            {
                var attribute = property.GetAttribute <DelimitedFieldAttribute>();

                if (attribute != default)
                {
                    var isLastInfinite = lastValueInfinite &&
                                         property == properties.Last();

                    if (fieldSetters.ContainsKey(attribute.Index))
                    {
                        throw new PropertyAlreadySetException(
                                  $"There can be only one property with {typeof(DelimitedFieldAttribute)} " +
                                  $"and index {attribute.Index} in {recordType}. ");
                    }

                    if (attribute.Count > 1 || isLastInfinite)
                    {
                        CreateFieldSetterCollection(
                            property: property,
                            fieldIndex: attribute.Index,
                            fieldCount: attribute.Count);
                    }
                    else
                    {
                        CreateFieldSetterSingle(
                            property: property,
                            fieldIndex: attribute.Index);
                    }
                }
            }

            var childProperties = recordType.GetChildProperties();

            foreach (var childProperty in childProperties)
            {
                var childFactory = GetChildFactory(childProperty);
                childFactory.InitializeDelimiteds();

                HeaderPatterns.UnionWith(childFactory.HeaderPatterns);
            }
        }