本文整理汇总了C#中Config.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Config.Add方法的具体用法?C# Config.Add怎么用?C# Config.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Config
的用法示例。
在下文中一共展示了Config.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Config_ChangeSet
public void Config_ChangeSet()
{
Config oldConfig = new Config();
oldConfig.Add("Test.Modified", new ConfigNode("NotModified"));
oldConfig.Add("Test.Removed", new ConfigNode("NotRemoved"));
Config newConfig = new Config(oldConfig);
newConfig.Remove("Test.Removed");
newConfig["Test.Modified"] = new ConfigNode("Modified");
newConfig.Add("Test.Added", new ConfigNode("Added"));
var changeSet = ConfigLoader.GenerateChangeSet(oldConfig, newConfig);
Assert.IsTrue(changeSet.ContainsNodeWithKey("Test.Modified"), "Modified change not recorded");
Assert.IsTrue(changeSet.ContainsNodeWithKey("Test.Removed"), "Removed change not recorded");
Assert.IsTrue(changeSet.ContainsNodeWithKey("Test.Added"), "Added change not recorded");
Assert.AreEqual(ChangeType.Modified, changeSet.WithKey("Test.Modified").Type);
Assert.AreEqual(ChangeType.Removed, changeSet.WithKey("Test.Removed").Type);
Assert.AreEqual(ChangeType.Added, changeSet.WithKey("Test.Added").Type);
Assert.AreEqual("NotModified", changeSet.WithKey("Test.Modified").Old.Value);
Assert.AreEqual("Modified", changeSet.WithKey("Test.Modified").New.Value);
Assert.AreEqual("NotRemoved", changeSet.WithKey("Test.Removed").Old.Value);
Assert.AreEqual(null, changeSet.WithKey("Test.Removed").New);
Assert.AreEqual(null, changeSet.WithKey("Test.Added").Old);
Assert.AreEqual("Added", changeSet.WithKey("Test.Added").New.Value);
}
示例2: ParseLine
private static void ParseLine(string line, Config config, Dictionary<string, string> currentMetadata, List<string> currentComments)
{
Match ma;
if ((ma = regexes["metadata"].Match(line)).Success)
{
currentMetadata.Add(ma.Groups["key"].Value.Trim(), ma.Groups["value"].Value);
}
else if ((ma = regexes["comment"].Match(line)).Success)
{
currentComments.Add(ma.Groups["comment"].Value);
}
else if ((ma = regexes["value"].Match(line)).Success)
{
ConfigNode node = new ConfigNode(ma.Groups["value"].Value);
foreach (var m in currentMetadata)
{
node.Metadata.Add(m.Key, m.Value);
}
foreach (var c in currentComments)
{
node.Comments.Add(c);
}
currentMetadata.Clear();
currentComments.Clear();
config.Add(ma.Groups["key"].Value.Trim(), node);
}
else if (regexes["whitespace"].Match(line).Success)
{
currentComments.Add("whitespace"); // Indicates whitespace. Printed out as whitespace. Sorry...
}
else
{
throw new InvalidDataException("Invalid config format");
}
}
示例3: CheckConfig
static void CheckConfig(string fName)
{
Config m_serverConf = new Config(fName);
m_serverConf.Load();
int oInt;
bool oBool;
string oStr;
Console.ForegroundColor = ConsoleColor.Yellow;
if (!m_serverConf.GetValue("passwordlen", out oInt))
{
Console.WriteLine("Setting default config value passwordlen=8");
m_serverConf.Add("general", "passwordlen", 8);
}
if (!m_serverConf.GetValue("passwordenc", out oBool))
{
Console.WriteLine("Setting default config value passwordenc=true");
m_serverConf.Add("general", "passwordenc", true);
}
if (!m_serverConf.GetValue("loggedinusers", out oInt))
{
Console.WriteLine("Setting default config value loggedinusers=50");
m_serverConf.Add("general", "loggedinusers", 50);
}
if(!m_serverConf.GetValue(ConfigConst.CONF_SERVER, ConfigConst.CONF_SERVER_DUAL, out oBool))
{
Console.WriteLine("Setting default config value dualmode=false");
m_serverConf.Add(ConfigConst.CONF_SERVER, ConfigConst.CONF_SERVER_DUAL, false);
}
if (!m_serverConf.GetValue("server", "bindaddress", out oStr))
{
Console.WriteLine("Setting default config value bindaddress=0.0.0.0");
m_serverConf.Add("server", "bindaddress", "0.0.0.0");
}
if (!m_serverConf.GetValue("server", "port", out oInt))
{
Console.WriteLine("Setting default config value port=8085");
m_serverConf.Add("server", "port", 8085);
}
if(!m_serverConf.GetValue(ConfigConst.CONF_GAME, ConfigConst.CONF_GAME_START_MAP, out oInt))
{
Console.WriteLine("Setting default config value startmap=0");
m_serverConf.Add(ConfigConst.CONF_GAME, ConfigConst.CONF_GAME_START_MAP, 0);
}
if (!m_serverConf.GetValue(ConfigConst.CONF_GAME, ConfigConst.CONF_GAME_START_X, out oInt))
{
Console.WriteLine("Setting default config value startx=29");
m_serverConf.Add(ConfigConst.CONF_GAME, ConfigConst.CONF_GAME_START_X, 29);
}
if (!m_serverConf.GetValue(ConfigConst.CONF_GAME, ConfigConst.CONF_GAME_START_Y, out oInt))
{
Console.WriteLine("Setting default config value starty=79");
m_serverConf.Add(ConfigConst.CONF_GAME, ConfigConst.CONF_GAME_START_Y, 79);
}
if (!m_serverConf.GetValue("database", "dbuser", out oStr))
{
Console.ResetColor();
Console.WriteLine("Enter a username for the database connection: ");
string user = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Setting config value dbuser=" + user);
m_serverConf.Add("database", "dbuser", user);
}
if (!m_serverConf.GetValue("database", "dbpass", out oStr))
{
Console.ResetColor();
Console.WriteLine("Enter the password for the specified user: ");
string pass = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Setting config value dbpass=" + pass);
m_serverConf.Add("database", "dbpass", pass);
}
if (!m_serverConf.GetValue("database", "dbaddr", out oStr))
{
Console.ResetColor();
Console.WriteLine("Enter the server address for the database connection: ");
string addr = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Setting config value dbaddr=" + addr);
m_serverConf.Add("database", "dbaddr", addr);
}
m_serverConf.SaveChanges();
Console.ResetColor();
}