本文整理汇总了C#中Config.attr方法的典型用法代码示例。如果您正苦于以下问题:C# Config.attr方法的具体用法?C# Config.attr怎么用?C# Config.attr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Config
的用法示例。
在下文中一共展示了Config.attr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Comments
public void Comments()
{
Config config = new Config(files[1]);
Assert.AreEqual<int>(1, config.attr<List<string>>("array").Count);
Assert.AreEqual<int>(1, config.attr<string[]>("array").Length);
Assert.AreEqual<int>(25, config.attr<int>("number"));
Assert.AreEqual<string>(@"; comments can be any line starting with a # or semi-colon
also any line that does not have an equal sign are considered a comment.", config.comment("number"));
Assert.AreEqual<string>("# comments shoudl be rewritten in the correct spot every time..", config.comment("array"));
}
示例2: Main
static int Main( string[] args )
{
Config config = new Config();
string site = "",
password = "",
username = "",
cachefile = "";
//bool allowalpha = true,
// allowdigits = true,
// allowsymbols = true;
bool addsymbols = true;
bool setclip = true;
bool fl_config = false;
int passlen = 26;
config.read(true);
if (config.contains("cachefile")) {
cachefile = config.attr<string>("cachefile");
} else {
cachefile = "createpw.enc";
}
for (int i = 0; i < args.Length; i++) {
string a = args[i];
if (a.Length == 0) {
continue;
}
if (a.StartsWith("/") || a.StartsWith("-") || a.StartsWith("!")) {
while (a.StartsWith("/") || a.StartsWith("-")) {
a = a.Substring(1);
}
string al = a.ToLowerInvariant();
if (al == "?" || al.StartsWith("h")) {
usage();
return 0;
} else if (al.Equals("pause") || al.Equals("!pause") || al.Equals("nopause") || al.Equals("no-pause")) {
pause = al.Equals("pause");
} else if (al.StartsWith("q") || al.StartsWith("!q") || al.StartsWith("noq") || al.StartsWith("no-q")) {
quiet = al.StartsWith("q");
} else if (al.StartsWith("v") || al.StartsWith("!v") || al.StartsWith("nov") || al.StartsWith("no-v")) {
verbose = al.StartsWith("v");
} else if (al.Equals("config")) {
fl_config = true;
} else if (al.StartsWith("cache") || al.StartsWith("!cache") || al.Equals("nocache") || al.Equals("no-cache")) {
useCache = al.StartsWith("cache");
} else if (al.StartsWith("p")) {
int j = al.IndexOfAny(new char[] { ':', '=' });
if (j > -1) {
password = a.Substring(j + 1).Trim();
} else {
if (args.Length > i) {
password = args[i + 1];
} else {
Console.WriteLine("Missing master password argument.");
}
}
} else if (al.StartsWith("len") || al.StartsWith("passlen") || al.StartsWith("pass-len")) {
int j = al.IndexOfAny(new char[] { ':', '=' });
if (j > -1) {
if (!int.TryParse(al.Substring(j + 1).Trim(), out passlen)) {
Console.WriteLine("Could not parse the password length: " + args[i + 1]);
}
} else {
if (args.Length > i) {
if (!int.TryParse(args[i + 1], out passlen)) {
Console.WriteLine("Could not parse the password length: " + args[i + 1]);
}
} else {
Console.WriteLine("Missing new password length argument.");
}
}
} else if (al == "clip" || al == "noclip" || al == "no-clip") {
setclip = (al == "clip");
//} else if (al.StartsWith("a") || al.StartsWith("!a") || al.StartsWith("noa") || al.StartsWith("no-a")) {
// allowalpha = al.StartsWith("a");
//} else if (al.StartsWith("d") || al.StartsWith("!d") || al.StartsWith("nod") || al.StartsWith("no-d")) {
// allowdigits = al.StartsWith("d");
} else if (al.StartsWith("s") || al.StartsWith("adds") || al.StartsWith("add-s")
|| al.StartsWith("!s") || al.StartsWith("nos") || al.StartsWith("no-s")) {
addsymbols = al.StartsWith("s") || al.StartsWith("adds") || al.StartsWith("add-s");
} else if (al.StartsWith("l")) {
//int pos;
//if ((pos = a.IndexOf(":")) > -1 || (pos = a.IndexOf("=")) > -1) {
// if (!int.TryParse(a.Substring(pos), out passlen)) {
// Console.WriteLine("Error in length argument: " + a);
// return 2;
// }
//} else {
//.........这里部分代码省略.........
示例3: ConstructorVsRead
public void ConstructorVsRead()
{
Config config = new Config(files[1]);
Assert.AreEqual<int>(1, config.attr<List<string>>("array").Count);
Assert.AreEqual<int>(1, config.attr<string[]>("array").Length);
Assert.AreEqual<int>(25, config.attr<int>("number"));
config = new Config();
config.read(files[1]);
Assert.AreEqual<int>(1, config.attr<List<string>>("array").Count);
Assert.AreEqual<int>(1, config.attr<string[]>("array").Length);
Assert.AreEqual<short>(25, config.attr<short>("number"));
Assert.AreEqual<int>(25, config.attr<int>("number"));
Assert.AreEqual<long>(25, config.attr<long>("number"));
Assert.AreEqual<ulong>(25, config.attr<ulong>("number"));
}
示例4: TheBasics
public void TheBasics()
{
Config config = new Config();
config.read(files[0]);
Assert.AreEqual<int>(1, config.attr<List<string>>("array").Count);
Assert.AreEqual<int>(1, config.attr<string[]>("array").Length);
Assert.AreEqual<int>(25, config.attr<int>("number"));
}