コード例 #1
0
        private object DeserializeSection(ConfigSectionInfo sectionInfo)
        {
            var elems = _serializer.GetSectionContent(SectionName.Create(sectionInfo));

            if (elems.Length <= 0)
            {
                return(sectionInfo.Serializer.CreateDefaultSection());
            }
            var elem = elems[0];

            if (elems.Length > 1)
            {
                if (!sectionInfo.AllowMerge)
                {
                    throw new ApplicationException($"Section '{sectionInfo.Name}' does not allow merge");
                }
                else
                {
                    for (var i = 1; i < elems.Length; i++)
                    {
                        foreach (var sibChild in elems[i].Nodes())
                        {
                            elem.Add(sibChild, true);
                        }
                    }
                }
            }
            return(sectionInfo.Serializer.Deserialize(elem.CreateReader()));
        }