コード例 #1
0
ファイル: Ini.cs プロジェクト: TinSyner/github_spider
        public static Ini FromElements(IEnumerable <IniElement> elemes)
        {
            var ret = new Ini();

            ret.Elements.AddRange(elemes);
            if (ret.Elements.Count > 0)
            {
                IniSection section = null;

                if (ret.Elements[ret.Elements.Count - 1] is IniBlankLine)
                {
                    ret.Elements.RemoveAt(ret.Elements.Count - 1);
                }
                foreach (var element in ret.Elements)
                {
                    var el = element;
                    if (el is IniSectionStart)
                    {
                        section = new IniSection(ret, (IniSectionStart)el);
                        ret.Sections.Add(section);
                    }
                    else if (section != null)
                    {
                        section.Elements.Add(el);
                    }
                    else if (ret.Sections.Exists(a => a.Name == ""))
                    {
                        ret.Sections[0].Elements.Add(el);
                    }
                    else if (el is IniValue)
                    {
                        section = new IniSection(ret, IniSectionStart.FromName(""));
                        section.Elements.Add(el);
                        ret.Sections.Add(section);
                    }
                }
            }
            return(ret);
        }
コード例 #2
0
ファイル: Ini.cs プロジェクト: kevins1022/Altman
		public static Ini FromElements(IEnumerable<IniElement> elemes)
		{
			var ret = new Ini();
			ret.Elements.AddRange(elemes);
			if (ret.Elements.Count > 0)
			{
				IniSection section = null;

				if (ret.Elements[ret.Elements.Count - 1] is IniBlankLine)
					ret.Elements.RemoveAt(ret.Elements.Count - 1);
				foreach (var element in ret.Elements)
				{
					var el = element;
					if (el is IniSectionStart)
					{
						section = new IniSection(ret, (IniSectionStart)el);
						ret.Sections.Add(section);
					}
					else if (section != null)
						section.Elements.Add(el);
					else if (ret.Sections.Exists(a => a.Name == ""))
						ret.Sections[0].Elements.Add(el);
					else if (el is IniValue)
					{
						section = new IniSection(ret, IniSectionStart.FromName(""));
						section.Elements.Add(el);
						ret.Sections.Add(section);
					}
				}
			}
			return ret;
		}
コード例 #3
0
ファイル: Ini.cs プロジェクト: kevins1022/Altman
		public IniSection this[string sectionName]
		{
			get
			{
				var sect = GetSection(sectionName);
				if (sect != null)
					return sect;
				IniSectionStart start;
				if (Sections.Count > 0)
				{
					var prev = Sections[Sections.Count - 1].SectionStart;
					start = prev.CreateNew(sectionName);
				}
				else
					start = IniSectionStart.FromName(sectionName);
				if (IniSettings.SeparateSection)
				{
					Elements.Add(new IniBlankLine(1));
				}
				Elements.Add(start);
				sect = new IniSection(this, start);
				Sections.Add(sect);
				return sect;
			}
		}
コード例 #4
0
ファイル: Ini.cs プロジェクト: kevins1022/Altman
		public void WriteSection(IniSection section)
		{
			WriteElement(section.SectionStart);
			for (var i = section.Parent.Elements.IndexOf(section.SectionStart) + 1; i < section.Parent.Elements.Count; i++)
			{
				if (section.Parent.Elements[i] is IniSectionStart)
					break;
				WriteElement(section.Parent.Elements[i]);
			}
		}