本文整理汇总了C#中CmdRequest.TryGetValueOr方法的典型用法代码示例。如果您正苦于以下问题:C# CmdRequest.TryGetValueOr方法的具体用法?C# CmdRequest.TryGetValueOr怎么用?C# CmdRequest.TryGetValueOr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CmdRequest
的用法示例。
在下文中一共展示了CmdRequest.TryGetValueOr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteRequest
public override CmdResult ExecuteRequest(CmdRequest args)
{
string filename;
if (args.TryGetValue("save", out filename))
{
FileStream w = null;
try
{
w = File.OpenWrite(filename);
StreamWriter sw = new StreamWriter(w);
SysVarHtml((s, args0) =>
{
try
{
sw.WriteLine(DLRConsole.SafeFormat(s, args0));
}
catch (Exception)
{
return;
}
}, true);
}
finally
{
if (w != null) w.Close();
;
}
return Success("Wrote " + filename);
}
if (args.TryGetValue("load", out filename))
{
LoadSysVarHtml(File.OpenRead(filename));
return Success("Loaded " + filename);
}
if (args.ContainsFlag("htmldoc"))
{
StringBuilder sw = new StringBuilder(1024*900);
SysVarHtml((s, ags) => sw.AppendFormat(s, ags), false);
return Success(sw.ToString());
}
bool exactMatch = args.ContainsFlag("--exact");
bool caseSensitive = args.ContainsFlag("--case");
int used = 0;
var sysvars = GetSysVars();
string find;
if (!args.TryGetValueOr("key", 0, out find))
{
// display all
foreach (var sv in sysvars)
{
var svv = sv;
WriteLine(string.Format("{0}={1} //{2}", (svv.Key), svv.Value, svv.Comments));
}
return Success("count=" + sysvars.Count);
}
if (!caseSensitive) find = find.ToLower();
var setThese = ScriptManager.FindMatchingSysvars(sysvars, find, exactMatch, caseSensitive);
int found = 0;
foreach (var svv in setThese)
{
{
found++;
WriteLine(svv.DebugInfo);
}
}
string value;
if (!args.TryGetValueOr("value", 1, out value))
{
return Success("Found sysvars: " + found);
}
int changed = 0;
foreach (var one in setThese)
{
try
{
one.Value = value;
AddSuccess("Set sysvar: " + one.Key + " to " + one.Value);
changed++;
}
catch (Exception e)
{
}
}
return Success("set vars = " + changed);
}