Example #1
0
        void ProcessSection(Section section, ContainerClass sections, string datapath = null, FileSystem vfs = null)
        {
            var tgt = sections.GetSection(section.Name);

            if (tgt == null)
            {
                FLLog.Warning("Ini", "Unknown section " + section.Name + FormatLine(section.File, section.Line));
                return;
            }
            if (tgt.Field == null)
            {
                GetFromSection(section, tgt.Type, this);
            }
            else
            {
                if (tgt.Delimiters != null)
                {
                    foreach (var ch in Chunk(tgt.Delimiters, section))
                    {
                        var childObject = GetFromSection(ch, tgt.Type, null, datapath, vfs);
                        if (childObject != null)
                        {
                            var list = tgt.Field.GetValue(this);
                            tgt.Add.Invoke(list, new object[] { childObject });
                        }
                    }
                }
                else
                {
                    var parsed = GetFromSection(section, tgt.Type, null, datapath, vfs);
                    if (parsed != null)
                    {
                        if (tgt.Add != null)
                        {
                            var list = tgt.Field.GetValue(this);
                            tgt.Add.Invoke(list, new object[] { parsed });
                        }
                        else
                        {
                            tgt.Field.SetValue(this, parsed);
                        }
                    }
                }
            }
        }
        void ProcessSection(Section section, ContainerClass sections, string datapath = null, FileSystem vfs = null)
        {
            var tgt = sections.GetSection(section.Name);

            if (tgt == null)
            {
                FLLog.Warning("Ini", "Unknown section " + section.Name + FormatLine(section.File, section.Line));
                return;
            }
            if (tgt.Field == null)
            {
                GetFromSection(section, tgt.Type, this);
            }
            else
            {
                if (tgt.Delimiters != null)
                {
                    foreach (var ch in Chunk(tgt.Delimiters, section))
                    {
                        var childObject = GetFromSection(ch, tgt.Type, null, datapath, vfs);
                        if (childObject != null)
                        {
                            var list = (IList)tgt.Field.GetValue(this);
                            list.Add(childObject);
                        }
                    }
                }
                else
                {
                    var parsed = GetFromSection(section, tgt.Type, null, datapath, vfs);
                    if (parsed != null)
                    {
                        if (tgt.IsList)
                        {
                            var list = (IList)tgt.Field.GetValue(this);
                            if (tgt.AttachToParent)
                            {
                                var count = list.Count;
                                if (count <= 0)
                                {
                                    FLLog.Warning("Ini", $"Section {section.Name} has no parent {FormatLine(section.File, section.Line)}");
                                    return;
                                }
                                var  parent     = list[count - 1];
                                bool success    = false;
                                var  parentInfo = GetSectionInfo(parent.GetType());
                                foreach (var cs in parentInfo.ChildSections)
                                {
                                    if (cs.Name.Equals(section.Name, StringComparison.OrdinalIgnoreCase))
                                    {
                                        var ls2 = (IList)cs.Field.GetValue(parent);
                                        ls2.Add(parsed);
                                        success = true;
                                        break;
                                    }
                                }
                                if (!success)
                                {
                                    FLLog.Warning("Ini",
                                                  $"Type {parentInfo.GetType().Name} does not accept child section {section.Name} {FormatLine(section.File, section.Line)}");
                                }
                            }
                            else
                            {
                                list.Add(parsed);
                            }
                        }
                        else
                        {
                            tgt.Field.SetValue(this, parsed);
                        }
                    }
                }
            }
        }