本文整理汇总了C#中Options.AddSwitch方法的典型用法代码示例。如果您正苦于以下问题:C# Options.AddSwitch方法的具体用法?C# Options.AddSwitch怎么用?C# Options.AddSwitch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Options
的用法示例。
在下文中一共展示了Options.AddSwitch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static int Main(string[] args)
{
try
{
var directories = new List<string>();
var files = new List<string>();
var programCommand = Command.None;
Func<CompositionContractInfo, bool> contractPredicate = c => false;
Func<CompositionInfo, PartDefinitionInfo, bool> partPredicate = (ci, p) => false;
var verbose = false;
var whitelist = new RejectionWhitelist();
var opts = new Options();
opts.Add<string>("dir", @"C:\MyApp\Parts", "Specify directories to search for parts.",
d => directories.Add(d));
opts.Add<string>("file", "MyParts.dll", "Specify assemblies to search for parts.",
f => files.Add(f));
opts.AddSwitch("verbose", "Print verbose information on each part.",
() => verbose = true);
var programCommandGroup = new ExclusiveGroup();
opts.Add<string>("type", "MyNamespace.MyType", "Print details of the given part type.", t => {
programCommand = Command.PrintParts;
partPredicate = AddToPredicate(partPredicate, (ci, p) => p == ci.GetPartDefinitionInfo(t));
},
programCommandGroup);
opts.Add<string>("importers", "MyContract", "List importers of the given contract.", i => {
programCommand = Command.PrintParts;
partPredicate = AddToPredicate(partPredicate, (ci, p) => p.ImportsContract(i));
},
programCommandGroup);
opts.Add<string>("exporters", "MyContract", "List exporters of the given contract.", e => {
programCommand = Command.PrintParts;
partPredicate = AddToPredicate(partPredicate, (ci, p) => p.ExportsContract(e));
},
programCommandGroup);
opts.AddSwitch("rejected", "List all rejected parts.", () => {
programCommand = Command.PrintParts;
partPredicate = AddToPredicate(partPredicate, (ci, p) => p.IsRejected);
},
programCommandGroup);
opts.AddSwitch("causes", "List root causes - parts with errors not related to the rejection of other parts.", () => {
programCommand = Command.PrintParts;
partPredicate = AddToPredicate(partPredicate, (ci, p) => p.IsPrimaryRejection);
},
programCommandGroup);
opts.Add<string>("whitelist", "RejectionWhitelist.txt", "Specify parts that may be validly rejected; requres the /rejected or /causes commands.",
w => whitelist = new RejectionWhitelist(w));
opts.AddSwitch("parts", "List all parts found in the source assemblies.", () => {
programCommand = Command.PrintParts;
partPredicate = AddToPredicate(partPredicate, (ci, p) => true);
},
programCommandGroup);
opts.AddSwitch("?", "Print usage.",
() => programCommand = Command.PrintUsage, programCommandGroup);
var contractsSubgroup = new InclusiveSubroup(programCommandGroup);
opts.AddSwitch("imports", "Find imported contracts.", () => {
programCommand = Command.PrintContracts;
contractPredicate = AddToPredicate(contractPredicate, c => c.Importers.Any());
},
contractsSubgroup);
opts.AddSwitch("exports", "Find exported contracts.", () => {
programCommand = Command.PrintContracts;
contractPredicate = AddToPredicate(contractPredicate, c => c.Exporters.Any());
},
contractsSubgroup);
opts.Parse(args);
return Run(directories, files, programCommand, contractPredicate, partPredicate, verbose, whitelist, opts);
}
catch (Exception ex)
{
Console.Write("Error: ");
Console.WriteLine(ex.Message);
return 1;
}
}