Beispiel #1
0
        public ChoIniSectionNode AddSection(string sectionName)
        {
            if (Contains(sectionName))
            {
                throw new ChoIniDocumentException(String.Format("Failed to add `{0}` section. Found duplicate node. Please check in the INI document and its sub-documents.", sectionName));
            }

            ChoIniSectionNode iniSection = new ChoIniSectionNode(this.OwnerDocument, sectionName);

            iniSection._parentIniSectionNode = this;
            return(AddIniNode(iniSection) as ChoIniSectionNode);
        }
Beispiel #2
0
        internal bool AddSection(ChoIniSectionNode iniSectionNode)
        {
            ChoGuard.ArgumentNotNullOrEmpty(iniSectionNode, "IniSectionNode");

            if (Contains(iniSectionNode.Name))
            {
                throw new ChoIniDocumentException(String.Format("Failed to add duplicate '{0}' section. Please check in the INI document and its sub-documents.", iniSectionNode.Name));
            }

            iniSectionNode._parentIniSectionNode = this;
            return(AddIniNode(iniSectionNode) != null);
        }
Beispiel #3
0
        public void UncommentSection(string sectionName)
        {
            ChoIniSectionNode foundSection = GetSection(sectionName);

            if (foundSection == null)
            {
                throw new ChoIniDocumentException(String.Format("Can't find `{0}` section.", sectionName));
            }
            else
            {
                UncommentSection(foundSection);
            }
        }
Beispiel #4
0
        //public bool InsertBeforeSection(string sectionName, ChoIniSectionNode iniSectionNode)
        //{
        //    ChoGuard.ArgumentNotNullOrEmpty(sectionName, "SectionName");
        //    ChoGuard.ArgumentNotNullOrEmpty(iniSectionNode, "IniSectionNode");

        //    ChoIniSectionNode insertBeforeSection = null;

        //    if (!TryGetSection(sectionName, out insertBeforeSection))
        //        throw new ChoIniDocumentException(String.Format("Can't find {0} section.", sectionName));
        //    else
        //        return InsertBeforeIniNode(GetIndex(insertBeforeSection), iniSectionNode);
        //}

        //public bool InsertAfterSection(string sectionName, ChoIniSectionNode iniSectionNode)
        //{
        //    ChoGuard.ArgumentNotNullOrEmpty(sectionName, "SectionName");
        //    ChoGuard.ArgumentNotNullOrEmpty(iniSectionNode, "IniSectionNode");

        //    ChoIniSectionNode insertBeforeSection = null;

        //    if (!TryGetSection(sectionName, out insertBeforeSection))
        //        throw new ChoIniDocumentException(String.Format("Can't find {0} section.", sectionName));
        //    else
        //        return InsertBeforeIniNode(GetIndex(insertBeforeSection), iniSectionNode);
        //}

        //public ChoIniSectionNode CreateSection(string sectionName)
        //{
        //    if (Contains(sectionName))
        //        throw new ChoIniDocumentException(String.Format("Duplicate `{0}` section found. Please check in the INI document and its sub-documents.", sectionName));

        //    ChoIniSectionNode iniSection = new ChoIniSectionNode(this.OwnerDocument, sectionName);
        //    iniSection._parentIniSectionNode = this;
        //    return iniSection;
        //}

        public bool DeleteSection(string sectionName)
        {
            ChoIniSectionNode foundSection = GetSection(sectionName);

            if (foundSection == null)
            {
                throw new ChoIniDocumentException(String.Format("Can't find `{0}` section.", sectionName));
            }
            else
            {
                return(DeleteSection(foundSection));
            }
        }
Beispiel #5
0
        private string GetName()
        {
            StringBuilder name = new StringBuilder();

            ChoIniSectionNode iniSectionNode = this;

            name.Append(_name);
            while (iniSectionNode._parentIniSectionNode != null)
            {
                if (iniSectionNode._parentIniSectionNode.IsRootSection)
                {
                    break;
                }

                name.Insert(0, '/');
                name.Insert(0, iniSectionNode._parentIniSectionNode._name);
                iniSectionNode = iniSectionNode._parentIniSectionNode;
            }

            return(name.ToString());
        }
Beispiel #6
0
        public ChoIniSectionNode GetSection(string sectionName)
        {
            foreach (ChoIniNode iniNode in _iniNodes)
            {
                if (iniNode is ChoIniSectionNode)
                {
                    if (String.Compare(((ChoIniSectionNode)iniNode).Name, sectionName, false) == 0)
                    {
                        return(iniNode as ChoIniSectionNode);
                    }
                }
                else if (iniNode is ChoIniIncludeFileNode)
                {
                    ChoIniSectionNode sectionNode = ((ChoIniIncludeFileNode)iniNode).GetSection(sectionName);
                    if (sectionNode != null)
                    {
                        return(sectionNode);
                    }
                }
            }

            return(null);
        }
Beispiel #7
0
        public bool TryGetSection(string sectionName, out ChoIniSectionNode section)
        {
            section = GetSection(sectionName);

            return(section != null);
        }
Beispiel #8
0
 internal void UncommentSection(ChoIniSectionNode section)
 {
     section.Uncomment();
 }
Beispiel #9
0
 internal bool CommentSection(ChoIniSectionNode section)
 {
     return(section.Comment());
 }
Beispiel #10
0
 internal bool DeleteSection(ChoIniSectionNode section)
 {
     return(Remove(section));
 }
 public bool TryGetSection(string sectionName, out ChoIniSectionNode section)
 {
     return(_iniDocument.TryGetSection(sectionName, out section));
 }