本文整理汇总了C#中Config.SetString方法的典型用法代码示例。如果您正苦于以下问题:C# Config.SetString方法的具体用法?C# Config.SetString怎么用?C# Config.SetString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Config
的用法示例。
在下文中一共展示了Config.SetString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test003_PutRemote
public virtual void Test003_PutRemote()
{
Config c = new Config();
c.SetString("sec", "ext", "name", "value");
c.SetString("sec", "ext", "name2", "value2");
string expText = "[sec \"ext\"]\n\tname = value\n\tname2 = value2\n";
NUnit.Framework.Assert.AreEqual(expText, c.ToText());
}
示例2: TestQuotingForSubSectionNames
public virtual void TestQuotingForSubSectionNames()
{
string resultPattern = "[testsection \"{0}\"]\n\ttestname = testvalue\n";
string result;
Config config = new Config();
config.SetString("testsection", "testsubsection", "testname", "testvalue");
result = MessageFormat.Format(resultPattern, "testsubsection");
NUnit.Framework.Assert.AreEqual(result, config.ToText());
config.Clear();
config.SetString("testsection", "#quotable", "testname", "testvalue");
result = MessageFormat.Format(resultPattern, "#quotable");
NUnit.Framework.Assert.AreEqual(result, config.ToText());
config.Clear();
config.SetString("testsection", "with\"quote", "testname", "testvalue");
result = MessageFormat.Format(resultPattern, "with\\\"quote");
NUnit.Framework.Assert.AreEqual(result, config.ToText());
}
示例3: Test007_readUserConfig
public virtual void Test007_readUserConfig()
{
MockSystemReader mockSystemReader = new MockSystemReader();
SystemReader.SetInstance(mockSystemReader);
string hostname = mockSystemReader.GetHostname();
Config userGitConfig = mockSystemReader.OpenUserConfig(null, FS.DETECTED);
Config localConfig = new Config(userGitConfig);
mockSystemReader.ClearProperties();
string authorName;
string authorEmail;
// no values defined nowhere
authorName = localConfig.Get(UserConfig.KEY).GetAuthorName();
authorEmail = localConfig.Get(UserConfig.KEY).GetAuthorEmail();
NUnit.Framework.Assert.AreEqual(Constants.UNKNOWN_USER_DEFAULT, authorName);
NUnit.Framework.Assert.AreEqual(Constants.UNKNOWN_USER_DEFAULT + "@" + hostname,
authorEmail);
NUnit.Framework.Assert.IsTrue(localConfig.Get(UserConfig.KEY).IsAuthorNameImplicit
());
NUnit.Framework.Assert.IsTrue(localConfig.Get(UserConfig.KEY).IsAuthorEmailImplicit
());
// the system user name is defined
mockSystemReader.SetProperty(Constants.OS_USER_NAME_KEY, "os user name");
localConfig.Uncache(UserConfig.KEY);
authorName = localConfig.Get(UserConfig.KEY).GetAuthorName();
NUnit.Framework.Assert.AreEqual("os user name", authorName);
NUnit.Framework.Assert.IsTrue(localConfig.Get(UserConfig.KEY).IsAuthorNameImplicit
());
if (hostname != null && hostname.Length != 0)
{
authorEmail = localConfig.Get(UserConfig.KEY).GetAuthorEmail();
NUnit.Framework.Assert.AreEqual("os user [email protected]" + hostname, authorEmail);
}
NUnit.Framework.Assert.IsTrue(localConfig.Get(UserConfig.KEY).IsAuthorEmailImplicit
());
// the git environment variables are defined
mockSystemReader.SetProperty(Constants.GIT_AUTHOR_NAME_KEY, "git author name");
mockSystemReader.SetProperty(Constants.GIT_AUTHOR_EMAIL_KEY, "[email protected]");
localConfig.Uncache(UserConfig.KEY);
authorName = localConfig.Get(UserConfig.KEY).GetAuthorName();
authorEmail = localConfig.Get(UserConfig.KEY).GetAuthorEmail();
NUnit.Framework.Assert.AreEqual("git author name", authorName);
NUnit.Framework.Assert.AreEqual("[email protected]", authorEmail);
NUnit.Framework.Assert.IsFalse(localConfig.Get(UserConfig.KEY).IsAuthorNameImplicit
());
NUnit.Framework.Assert.IsFalse(localConfig.Get(UserConfig.KEY).IsAuthorEmailImplicit
());
// the values are defined in the global configuration
userGitConfig.SetString("user", null, "name", "global username");
userGitConfig.SetString("user", null, "email", "[email protected]");
authorName = localConfig.Get(UserConfig.KEY).GetAuthorName();
authorEmail = localConfig.Get(UserConfig.KEY).GetAuthorEmail();
NUnit.Framework.Assert.AreEqual("global username", authorName);
NUnit.Framework.Assert.AreEqual("[email protected]", authorEmail);
NUnit.Framework.Assert.IsFalse(localConfig.Get(UserConfig.KEY).IsAuthorNameImplicit
());
NUnit.Framework.Assert.IsFalse(localConfig.Get(UserConfig.KEY).IsAuthorEmailImplicit
());
// the values are defined in the local configuration
localConfig.SetString("user", null, "name", "local username");
localConfig.SetString("user", null, "email", "[email protected]");
authorName = localConfig.Get(UserConfig.KEY).GetAuthorName();
authorEmail = localConfig.Get(UserConfig.KEY).GetAuthorEmail();
NUnit.Framework.Assert.AreEqual("local username", authorName);
NUnit.Framework.Assert.AreEqual("[email protected]", authorEmail);
NUnit.Framework.Assert.IsFalse(localConfig.Get(UserConfig.KEY).IsAuthorNameImplicit
());
NUnit.Framework.Assert.IsFalse(localConfig.Get(UserConfig.KEY).IsAuthorEmailImplicit
());
authorName = localConfig.Get(UserConfig.KEY).GetCommitterName();
authorEmail = localConfig.Get(UserConfig.KEY).GetCommitterEmail();
NUnit.Framework.Assert.AreEqual("local username", authorName);
NUnit.Framework.Assert.AreEqual("[email protected]", authorEmail);
NUnit.Framework.Assert.IsFalse(localConfig.Get(UserConfig.KEY).IsCommitterNameImplicit
());
NUnit.Framework.Assert.IsFalse(localConfig.Get(UserConfig.KEY).IsCommitterEmailImplicit
());
}
示例4: Test004_PutGetSimple
public virtual void Test004_PutGetSimple()
{
Config c = new Config();
c.SetString("my", null, "somename", "false");
NUnit.Framework.Assert.AreEqual("false", c.GetString("my", null, "somename"));
NUnit.Framework.Assert.AreEqual("[my]\n\tsomename = false\n", c.ToText());
}
示例5: TestTreeIteratorWithGitmodules
public virtual void TestTreeIteratorWithGitmodules()
{
ObjectId subId = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
string path = "sub";
Config gitmodules = new Config();
gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
.CONFIG_KEY_PATH, "sub");
gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
.CONFIG_KEY_URL, "git://example.com/sub");
RevCommit commit = testDb.GetRevWalk().ParseCommit(testDb.Commit().NoParents().Add
(Constants.DOT_GIT_MODULES, gitmodules.ToText()).Edit(new _PathEdit_397(subId, path
)).Create());
CanonicalTreeParser p = new CanonicalTreeParser();
p.Reset(testDb.GetRevWalk().GetObjectReader(), commit.Tree);
SubmoduleWalk gen = SubmoduleWalk.ForPath(db, p, "sub");
NUnit.Framework.Assert.AreEqual(path, gen.GetPath());
NUnit.Framework.Assert.AreEqual(subId, gen.GetObjectId());
NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), gen.GetDirectory
());
NUnit.Framework.Assert.IsNull(gen.GetConfigUpdate());
NUnit.Framework.Assert.IsNull(gen.GetConfigUrl());
NUnit.Framework.Assert.AreEqual("sub", gen.GetModulesPath());
NUnit.Framework.Assert.IsNull(gen.GetModulesUpdate());
NUnit.Framework.Assert.AreEqual("git://example.com/sub", gen.GetModulesUrl());
NUnit.Framework.Assert.IsNull(gen.GetRepository());
NUnit.Framework.Assert.IsFalse(gen.Next());
}
示例6: IndexWithGitmodules
public virtual void IndexWithGitmodules()
{
ObjectId subId = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
string path = "sub";
Config gitmodules = new Config();
gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
.CONFIG_KEY_PATH, "sub");
// Different config in the index should be overridden by the working tree.
gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
.CONFIG_KEY_URL, "git://example.com/bad");
RevBlob gitmodulesBlob = testDb.Blob(gitmodules.ToText());
gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
.CONFIG_KEY_URL, "git://example.com/sub");
WriteTrashFile(Constants.DOT_GIT_MODULES, gitmodules.ToText());
DirCache cache = db.LockDirCache();
DirCacheEditor editor = cache.Editor();
editor.Add(new _PathEdit_315(subId, path));
editor.Add(new _PathEdit_322(gitmodulesBlob, Constants.DOT_GIT_MODULES));
editor.Commit();
SubmoduleWalk gen = SubmoduleWalk.ForIndex(db);
NUnit.Framework.Assert.IsTrue(gen.Next());
NUnit.Framework.Assert.AreEqual(path, gen.GetPath());
NUnit.Framework.Assert.AreEqual(subId, gen.GetObjectId());
NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), gen.GetDirectory
());
NUnit.Framework.Assert.IsNull(gen.GetConfigUpdate());
NUnit.Framework.Assert.IsNull(gen.GetConfigUrl());
NUnit.Framework.Assert.AreEqual("sub", gen.GetModulesPath());
NUnit.Framework.Assert.IsNull(gen.GetModulesUpdate());
NUnit.Framework.Assert.AreEqual("git://example.com/sub", gen.GetModulesUrl());
NUnit.Framework.Assert.IsNull(gen.GetRepository());
NUnit.Framework.Assert.IsFalse(gen.Next());
}
示例7: Set
private void Set(Config rc, string key, string currentValue, string defaultValue)
{
if (defaultValue.Equals(currentValue))
{
Unset(rc, key);
}
else
{
rc.SetString(SECTION, Name, key, currentValue);
}
}