public void CreatesProperty() { var s = PropertyFactory.CreateProperty("foo", "bar", Grammar.DefaultDelimiters); var p = new IniProperty(s, null); Assert.AreEqual("foo", p.Name); Assert.AreEqual("bar", p.Value); }
public void IniFile_Property_Modify_Value() { var property = new IniProperty("PN", "PV"); property.Value = "PVnew"; Assert.AreEqual("PN", property.Name); Assert.AreEqual("PVnew", property.Value); }
public void IniFile_Property_Modify_Name() { var property = new IniProperty("PN", "PV") { Name = "PNnew" }; Assert.AreEqual("PNnew", property.Name); Assert.AreEqual("PV", property.Value); }
/// <inheritdoc /> public IniProperty Normalize(IniProperty source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(Options.IsCaseSensitive ? new IniProperty(source.Name, source.Value) : new IniProperty(source.Name.ToUpperInvariant(), source.Value)); }
// _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // ReadMethod // _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ private void ReadOneData(TIniTarget target) { var properties = GetAllPropertyInfo(); foreach (var line in File.ReadLines(FilePath, Encoding.Default)) { var iniProperty = new IniProperty(line); var targetProperty = properties.FirstOrDefault(x => x.Name.Equals(iniProperty.PropertyName)); targetProperty?.SetValue(target, iniProperty.Value); } }
/// <inheritdoc /> public bool TryNormalize(IniProperty source, out IniProperty destination) { if (source == null) { throw new ArgumentNullException(nameof(source)); } destination = Options.IsCaseSensitive ? new IniProperty(source.Name, source.Value) : new IniProperty(source.Name.ToUpperInvariant(), source.Value); return(true); }
public void AddsComment() { var s = PropertyFactory.CreateProperty("foo", "bar", Grammar.DefaultDelimiters); var p = new IniProperty(s, new IniFile()); p.AddComment("baz"); p.AddComment("qux"); Assert.IsTrue(p.Comments.Count() == 2); Assert.IsTrue(p.Comments.ElementAt(0) == "baz"); Assert.IsTrue(p.Comments.ElementAt(1) == "qux"); }
public void WriteToFile() { IniConfig config = new IniConfig(); IniSection section = config.AddSection("TestSection"); section.Comments.AddRange(new string[] { "Test1", "Comment2" }); IniProperty property = section.AddProperty("name", "Test", new string[] { "Property1", "TestProperty" }, new string[] { "Test1", "Test2" }); string content = IniWriter.WriteToString(config); File.WriteAllText(@"D:\ini-config.txt", content); }
private bool TryExtractProperty(string line, out IniProperty property) { int signIdx; if (line.Length > 1 && (signIdx = line.IndexOf( Options.PropertyNameValueDelimiter.ToString(), StringComparison.OrdinalIgnoreCase)) >= 0) { var name = line.Substring(0, signIdx); var value = signIdx == line.Length - 1 ? null : line.Substring(signIdx + 1, line.Length - 1 - signIdx); property = new IniProperty(name, value); return(true); } property = null; return(false); }
public void IniFile_Property_Create_Null() { var property = new IniProperty("Test", null); }
public void IniFile_Property_Modify_ValueNull() { var property = new IniProperty("PN", "PV"); property.Value = null; }
/// <summary> /// Normalizes the <see cref="IniProperty"/> /// using the <see cref="IniNormalizer.Default"/> instance. /// </summary> /// <param name="section">The section to normalize</param> /// <param name="result">The normalized section</param> /// <returns>True if instance normalized successfully, otherwise false</returns> public static bool TryNormalize(this IniProperty section, out IniProperty result) { return(IniNormalizer.Default.TryNormalize(section, out result)); }
/// <summary> /// Normalizes the <see cref="IniProperty"/> /// using the <see cref="IniNormalizer.Default"/> instance. /// </summary> /// <param name="section">The section to normalize</param> /// <returns>The normalized section</returns> public static IniProperty Normalize(this IniProperty section) { return(IniNormalizer.Default.Normalize(section)); }