Esempio n. 1
0
        public static void Read <T>(this CdsFile <T> file, TextReader reader)
            where T : CdsFile <T>, new()
        {
            var schema = CdsFile <T> .Schema;

            using (var scanner = new TextScanner(reader))
            {
                scanner.ReadProperties(schema.Fields, file);
                scanner.ReadSections(schema.Sections, file);
            }
        }
Esempio n. 2
0
        static IList ReadGroup(this TextScanner scanner, FileSection section)
        {
            var list = section.CreateList();

            while (!scanner.TryGetSectionEnd(section))
            {
                var item = section.CreateObject();
                scanner.ReadProperties(section.Schema.Fields, item);
                scanner.ReadSections(section.Schema.Sections, item);
                list.Add(item);
            }

            return(list);
        }
Esempio n. 3
0
        static void ReadSections(this TextScanner scanner, IReadOnlyList <FileSection> sections, object target)
        {
            foreach (var section in sections)
            {
                while (!scanner.TryGetSectionStart(section))
                {
                    if (!scanner.Read())
                    {
                        return;
                    }
                }

                if (!scanner.Read())
                {
                    return;
                }

                if (section.IsText)
                {
                    if (scanner.TryGetText(out var text))
                    {
                        section[target] = text;
                    }
                }
                else if (section.IsTable)
                {
                    section[target] = scanner.ReadTable(section);
                }
                else if (section.IsGroup)
                {
                    section[target] = scanner.ReadGroup(section);
                }
                else
                {
                    section[target] = section.CreateObject();
                    scanner.ReadProperties(section.Schema.Fields, section[target]);
                    scanner.ReadSections(section.Schema.Sections, section[target]);
                }

                if (!scanner.TrySkipSectionEnd(section))
                {
                    return;
                }
            }
        }