示例#1
0
        public string GetValue(string sectionName, string keyName)
        {
            IniSectionEntry sectionEntry = (IniSectionEntry)this.sections[sectionName];

            if (sectionEntry == null)
            {
                sectionEntry = new IniSectionEntry(sectionName);
                this.sections[sectionName] = sectionEntry;
            }

            IniFileEntry entry = (IniFileEntry)sectionEntry.Values[keyName];

            if (entry == null)
            {
                Helper.GetPrivateProfileStringA(sectionName, keyName, "$|VI_NOTFOUND|$", this.buffer, this.sizeMax, this.fileName);
                string value = this.buffer.ToString();

                if (value.Equals("$|VI_NOTFOUND|$"))
                {
                    entry = new IniFileEntry(keyName, this.defaultValueProvider.GetDefaultValue(sectionName, keyName));
                }
                else
                {
                    entry = new IniFileEntry(keyName, value);
                }

                sectionEntry.Values[keyName] = entry;
            }

            return(entry.Value);
        }
示例#2
0
        public void SetValue(string sectionName, string keyName, string value, bool deleteSectionIfEmpty)
        {
            IniSectionEntry sectionEntry = (IniSectionEntry)this.sections[sectionName];

            if (sectionEntry == null)
            {
                sectionEntry = new IniSectionEntry(sectionName);
                this.sections[sectionName] = sectionEntry;
            }

            sectionEntry.DeleteSectionIfEmpty = deleteSectionIfEmpty;

            IniFileEntry entry = (IniFileEntry)sectionEntry.Values[keyName];

            if (entry == null)
            {
                entry = new IniFileEntry(keyName, null);
                sectionEntry.Values[keyName] = entry;
            }

            entry.Value = value;
        }