当前位置: 首页>>代码示例>>C#>>正文


C# ConfigFile.GetValue方法代码示例

本文整理汇总了C#中ConfigFile.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigFile.GetValue方法的具体用法?C# ConfigFile.GetValue怎么用?C# ConfigFile.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConfigFile的用法示例。


在下文中一共展示了ConfigFile.GetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CaseSensitive

        public void CaseSensitive()
        {
            // create test data
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                configFile.SetValue("branch.BranchName1.remote", "origin1");
                configFile.Save();

                AddConfigValue(GetConfigFileName(), "branch.\"BranchName2\".remote", "origin2");
                AddConfigValue(GetConfigFileName(), "branch.\"branchName2\".remote", "origin3");
            }
            // verify
            {

                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);

                string remote = "branch.BranchName1.remote";
                CheckValueIsEqual(configFile, remote, "origin1");

                remote = "branch.branchName1.remote";
                CheckIsNotEqual(configFile, remote, "origin1");

                remote = "branch \"BranchName1\".remote";
                Assert.AreEqual(GetConfigValue(configFile.FileName, remote.Replace(" ", ".")), configFile.GetValue(remote), "git config --get");
                Assert.AreEqual("origin1", configFile.GetValue(remote), "ConfigFile");

                remote = "branch \"BranchName2\".remote";
                Assert.AreEqual(GetConfigValue(configFile.FileName, remote.Replace(" ", ".")), configFile.GetValue(remote), "git config --get");
                Assert.AreEqual("origin2", configFile.GetValue(remote), "ConfigFile");

                remote = "branch \"branchName2\".remote";
                Assert.AreNotEqual(GetConfigValue(configFile.FileName, remote.Replace(" ", ".")), "origin2", "git config --get");
                Assert.AreNotEqual("origin2", configFile.GetValue(remote), "ConfigFile");

                remote = "branch \"branchName2\".remote";
                Assert.AreEqual(GetConfigValue(configFile.FileName, remote.Replace(" ", ".")), configFile.GetValue(remote), "git config --get");
                Assert.AreEqual("origin3", configFile.GetValue(remote), "ConfigFile");

                remote = "branch \"branchname2\".remote";
                Assert.AreEqual(GetConfigValue(configFile.FileName, remote.Replace(" ", ".")), configFile.GetValue(remote), "git config --get");
                Assert.AreEqual("", configFile.GetValue(remote), "ConfigFile");
            }
        }
开发者ID:fraga,项目名称:gitextensionstest,代码行数:43,代码来源:ConfigFileTest.cs

示例2: CaseSensitive

        public void CaseSensitive()
        {
            // create test data
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
                configFile.AddValue("branch.BranchName1.remote", "origin1");
                configFile.Save();

                AddConfigValue(GetConfigFileName(), "branch.\"BranchName2\".remote", "origin2");
                AddConfigValue(GetConfigFileName(), "branch.\"branchName2\".remote", "origin3");
            }
            // verify
            {

                ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);

                string remote = "branch.BranchName1.remote";
                Assert.AreEqual("origin1", configFile.GetValue(remote), remote);

                remote = "branch.branchName1.remote";
                Assert.AreEqual("origin1", configFile.GetValue(remote), remote);

                remote = "branch \"branchName1\".remote";
                Assert.AreNotEqual("origin1", configFile.GetValue(remote), remote);

                remote = "branch \"BranchName2\".remote";
                Assert.AreEqual("origin2", configFile.GetValue(remote), remote);

                remote = "branch \"branchName2\".remote";
                Assert.AreNotEqual("origin2", configFile.GetValue(remote), remote);

                remote = "branch \"branchName2\".remote";
                Assert.AreEqual("origin3", configFile.GetValue(remote), remote);

                remote = "branch \"branchname2\".remote";
                Assert.AreEqual("", configFile.GetValue(remote), remote);

            }
        }
开发者ID:Nehle,项目名称:gitextensions,代码行数:39,代码来源:ConfigFileTest.cs

示例3: LoadSettingsFromClass

        void LoadSettingsFromClass(ConfigFile configFile, Type settingsClass, string sectionName)
        {
            foreach (FieldInfo fieldInfo in settingsClass.GetFields())
            {
                if (fieldInfo.FieldType == typeof(Dictionary<string, string>))
                {
                    Dictionary<string, string> dict = new Dictionary<string, string>();
                    var section = configFile.GetSection(sectionName);

                    foreach (var property in section.GetProperties())
                    {
                        var value = section.GetValue(property, "");
                        if (dict.ContainsKey(property))
                        {
                            dict.Add(property, value);
                        }
                        else
                        {
                            dict[property] = value;
                        }
                    }

                    fieldInfo.SetValue(null, dict);
                }
                else if (configFile.HasProperty(sectionName, fieldInfo.Name))
                {
                    string stringValue = configFile.GetValue(sectionName, fieldInfo.Name, "");
                    object value = StringConverter.Parse(stringValue, fieldInfo.FieldType);

                    fieldInfo.SetValue(null, value);
                }
            }

            foreach (Type nestedType in settingsClass.GetNestedTypes())
            {
                string newSectionName = sectionName;
                if (newSectionName.Length > 0)
                {
                    newSectionName += ".";
                }
                newSectionName += nestedType.Name;

                LoadSettingsFromClass(configFile, nestedType, newSectionName);
            }
        }
开发者ID:johang88,项目名称:triton,代码行数:45,代码来源:SettingsSerializer.cs

示例4: NewLineTest

        public void NewLineTest()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[bugtraq]");
                content.AppendLine("	url = http://192.168.0.1:8080/browse/%BUGID%");
                content.AppendLine("	message = This commit fixes %BUGID%");
                content.AppendLine("	append = true");
                content.AppendLine("	label = Key:");
                content.AppendLine("	number = true");
                content.AppendLine("	logregex = \\n([A-Z][A-Z0-9]+-/d+)");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("\\n([A-Z][A-Z0-9]+-/d+)", configFile.GetValue("bugtraq.logregex"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("bugtraq.logregex", "data\\nnewline");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("data\\nnewline", configFile.GetValue("bugtraq.logregex"));
            }
        }
开发者ID:christruman,项目名称:gitextensions,代码行数:36,代码来源:ConfigFileTest.cs

示例5: TestSetValueExisting

        public void TestSetValueExisting()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
            configFile.SetValue("section.key", "section.key");
            configFile.Save();

            configFile.SetValue("section.key", "section.keyoverwrite");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            Assert.AreEqual("section.keyoverwrite", configFile.GetValue("section.key"));
        }
开发者ID:Copro,项目名称:gitextensionstest,代码行数:12,代码来源:ConfigFileTest.cs

示例6: TestWithNullSettings

 public void TestWithNullSettings()
 {
     ConfigFile file = new ConfigFile(GetConfigFileName(), true);
     file.GetValue(null);
 }
开发者ID:Nehle,项目名称:gitextensions,代码行数:5,代码来源:ConfigFileTest.cs

示例7: RandomTestCase1

        public void RandomTestCase1()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[merge]");
                content.AppendLine("	tool = kdiff3");
                content.AppendLine("[mergetool \"kdiff3\"]");
                content.AppendLine("	path = c:/Program Files (x86)/KDiff3/kdiff3.exe");
                content.AppendLine("[user]");
                content.AppendLine("	name = Sergey Pustovit");
                content.AppendLine("	email = [email protected]");
                content.AppendLine("[core]");
                content.AppendLine("	safecrlf = false");
                content.AppendLine("	editor = C:/Program Files (x86)/Notepad++/notepad++.exe");
                content.AppendLine("[diff]");
                content.AppendLine("	tool = kdiff3");
                content.AppendLine("[difftool \"kdiff3\"]");
                content.AppendLine("	path = c:/Program Files (x86)/KDiff3/kdiff3.exe");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("Sergey Pustovit", configFile.GetValue("user.name"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("user.name", "newvalue");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("newvalue", configFile.GetValue("user.name"));
            }
        }
开发者ID:christruman,项目名称:gitextensions,代码行数:43,代码来源:ConfigFileTest.cs

示例8: SpacesInSubSectionTest

        public void SpacesInSubSectionTest()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[section \"sub section\"]");
                content.AppendLine("	test = test");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"test", configFile.GetValue("section.sub section.test"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("section.sub section.test", @"test2");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"test2", configFile.GetValue("section.sub section.test"));
            }
        }
开发者ID:christruman,项目名称:gitextensions,代码行数:31,代码来源:ConfigFileTest.cs

示例9: GetSubmoduleRemotePath

 public string GetSubmoduleRemotePath(string name)
 {
     var configFile = new ConfigFile(_workingdir + ".gitmodules");
     return configFile.GetValue("submodule." + name.Trim() + ".url").Trim();
 }
开发者ID:cocytus,项目名称:gitextensions,代码行数:5,代码来源:GitModule.cs

示例10: GetSubmoduleRemotePath

 public static string GetSubmoduleRemotePath(string name)
 {
     var configFile = new ConfigFile(Settings.WorkingDir + Settings.PathSeparator + ".gitmodules");
     return configFile.GetValue("submodule." + name.Trim() + ".url").Trim();
 }
开发者ID:avish,项目名称:gitextensions,代码行数:5,代码来源:GitCommandsHelper.cs

示例11: TestRemoveSettingSectionWithDotExisting

        public void TestRemoveSettingSectionWithDotExisting()
        {
            ConfigFile configFile = new ConfigFile(GetConfigFileName(), true);
            configFile.SetValue("submodule.test.test1.path1", "invalid");
            configFile.SetValue("submodule.test.test2.path1", "submodule.test.test2.path1");
            configFile.SetValue("submodule.test.test2.path2", "submodule.test.test2.path2");
            configFile.Save();

            configFile.RemoveSetting("submodule.test.test1.path1");
            configFile.Save();

            configFile = new ConfigFile(GetConfigFileName(), true);
            Assert.IsFalse(configFile.HasValue("submodule.test.test1.path1"));
            Assert.AreEqual("submodule.test.test2.path1", configFile.GetValue("submodule.test.test2.path1"));
            Assert.AreEqual("submodule.test.test2.path2", configFile.GetValue("submodule.test.test2.path2"));
        }
开发者ID:Copro,项目名称:gitextensionstest,代码行数:16,代码来源:ConfigFileTest.cs

示例12: GetMergeWith

 /// <summary>
 /// This method is a faster than the property above. The property reads the config file
 /// every time it is accessed. This method accepts a configfile what makes it faster when loading
 /// the revisiongraph.
 /// </summary>
 public string GetMergeWith(ConfigFile configFile)
 {
     string merge = configFile.GetValue(_mergeSettingName);
     return merge.StartsWith("refs/heads/") ? merge.Substring(11) : merge;
 }
开发者ID:kunigaku,项目名称:gitextensions,代码行数:10,代码来源:GitHead.cs

示例13: TestGetValue

 public void TestGetValue()
 {
     { //TESTDATA
         //Write test config
         File.WriteAllText(GetConfigFileName(), GetDefaultConfigFileContent(), GitModule.SystemEncoding);
     }
     ConfigFile file = new ConfigFile(GetConfigFileName(), true);
     Assert.AreEqual("value1", file.GetValue("section1.key1"));
     Assert.AreEqual("value2", file.GetValue("section2.subsection.key2"));
     Assert.AreEqual("value3", file.GetValue("section3.subsection.key3"));
 }
开发者ID:Copro,项目名称:gitextensionstest,代码行数:11,代码来源:ConfigFileTest.cs

示例14: UncPathTest2

        public void UncPathTest2()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine(@"[path]");
                content.AppendLine(@"	unc = \\\\test\\"); //<- escaped value in config file

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"\\test\", configFile.GetValue("path.unc"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("path.unc", @"\\test\test2\");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual(@"\\test\test2\", configFile.GetValue("path.unc"));
            }
        }
开发者ID:jystic,项目名称:gitextensions,代码行数:31,代码来源:ConfigFileTest.cs

示例15: TestWithSectionWithDot2

        public void TestWithSectionWithDot2()
        {
            { //TESTDATA
                StringBuilder content = new StringBuilder();

                content.AppendLine("[submodule.test.test]");
                content.AppendLine("path = test.test");

                //Write test config
                File.WriteAllText(GetConfigFileName(), content.ToString(), Encoding.UTF8);
            }

            //CHECK GET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("test.test", configFile.GetValue("submodule.test.test.path"));
            }

            //CHECK SET CONFIG VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                configFile.SetValue("submodule.test.test.path", "newvalue");
                configFile.Save();
            }

            //CHECK WRITTEN VALUE
            {
                ConfigFile configFile = new ConfigFile(GetConfigFileName());
                Assert.AreEqual("newvalue", configFile.GetValue("submodule.test.test.path"));
            }
        }
开发者ID:jystic,项目名称:gitextensions,代码行数:31,代码来源:ConfigFileTest.cs


注:本文中的ConfigFile.GetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。