Example #1
0
        public TDocumentDescriptor Parse(ITextSource textSource)
        {
            _ = textSource ?? throw new ArgumentNullException(nameof(textSource));

            var output = new TDocumentDescriptor();

            foreach (var property in typeof(TDocumentDescriptor).GetProperties())
            {
                var body = ParseTableContent(textSource.GetPagesText(), deserializeCollectionByRegexAttributes[property]?.BodyRegex);

                var value = this.textRegexDeserializator.Deserialize(
                    body,
                    property.PropertyType,
                    typeof(TDocumentDescriptor),
                    deserializeCollectionByRegexAttributes[property]?.CollectionRegex,
                    GetDeserializationRegexByType(typeof(TDocumentDescriptor)),
                    GetDeserializationRegexByType(property.PropertyType),
                    GetDeserializationRegexByType(property.PropertyType.GetCollectionElementType()));

                if (this.textRegexDeserializator.IsSimpleType(property.PropertyType))
                {
                    property.SetValue(output, property.GetValue(value));
                }
                else
                {
                    property.SetValue(output, value);
                }
            }

            return(output);
        }