eTime(rt); } public void SaveToStream(Stream stream) { StreamWriter SW = new StreamWriter(stream); SaveToStream(SW); SW.Dispose(); } public void SaveToStream(StreamWriter SW) { SW.WriteLine("[" + FSectionName + "]"); foreach (KeyValuePair
item in FDictionary) { SW.WriteLine(item.Key + "=" + item.Value); } } } /// /// 内存Ini解析 /// public class MemIniFile { private ArrayList List;//所有节点信息 private bool SectionExists(string SectionName) { foreach (IniSection ISec in List) { if (ISec.SectionName.ToLower() == SectionName.ToLower()) return true; } return false; } public IniSection FindSection(string SectionName) { foreach (IniSection ISec in List) { if (ISec.SectionName.ToLower() == SectionName.ToLower()) return ISec; } return null; } public MemIniFile() { List = new ArrayList(); } public void LoadFromStream(Stream stream) { StreamReader SR = new StreamReader(stream); List.Clear(); string st = null; IniSection Section = null;//节点 int equalSignPos; string key, value;
while (true) { st = SR.ReadLine(); if (st == null) break; st = st.Trim(); if (st == "") continue; if (st != "" &;&; st[0] == '[' &;&; st[st.Length - 1] == ']') { st = st.Remove(0,1); st = st.Remove(st.Length - 1,1); Section = FindSection(st); if (Section == null) { Section = new IniSection(st); List.Add(Section); } } else { if (Section == null) { Section = FindSection("UnDefSection"); if (Section == null) { Section = new IniSection("UnDefSection"); List.Add(Section); } } //开始解析 equalSignPos = st.IndexOf('='); if (equalSignPos != 0) { key = st.Substring(0, equalSignPos); value = st.Substring(equalSignPos + 1, st.Length - equalSignPos - 1); Section.AddKeyValue(key, value);//增加到节点 } else Section.AddKeyValue(st, ""); } } SR.Dispose(); } public void SaveToStream(Stream stream) { StreamWriter SW = new StreamWriter(stream); foreach (IniSection ISec in List) { ISec.SaveToStream(SW); } SW.Dispose(); } public string ReadValue(string SectionName, string key, string defaultv) { IniSection ISec = FindSection(SectionName); if (ISec != null) { return ISec.ReadValue(key, defaultv); } else return defaultv; }