public void LoadFromStream(Stream stream) { StreamReader SR = new StreamReader(stream, System.Text.ASCIIEncoding.Default); 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(); }