コード例 #1
0
ファイル: IniPropertyTests.cs プロジェクト: kangbudz/Martini
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: IniPropertyTests.cs プロジェクト: he-dev/Martini
        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);
        }
コード例 #4
0
ファイル: IniFileTest.cs プロジェクト: 3wayHimself/Medo
        public void IniFile_Property_Modify_Name()
        {
            var property = new IniProperty("PN", "PV")
            {
                Name = "PNnew"
            };

            Assert.AreEqual("PNnew", property.Name);
            Assert.AreEqual("PV", property.Value);
        }
コード例 #5
0
        /// <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));
        }
コード例 #6
0
        // _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
        //     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);
            }
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
ファイル: IniPropertyTests.cs プロジェクト: he-dev/Martini
        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");
        }
コード例 #9
0
ファイル: IniPropertyTests.cs プロジェクト: kangbudz/Martini
        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");
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: IniFileTest.cs プロジェクト: 3wayHimself/Medo
 public void IniFile_Property_Create_Null()
 {
     var property = new IniProperty("Test", null);
 }
コード例 #13
0
        public void IniFile_Property_Modify_ValueNull()
        {
            var property = new IniProperty("PN", "PV");

            property.Value = null;
        }
コード例 #14
0
 /// <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));
 }
コード例 #15
0
 /// <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));
 }