本文整理汇总了C#中Parser.AddDescription方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.AddDescription方法的具体用法?C# Parser.AddDescription怎么用?C# Parser.AddDescription使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.AddDescription方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RequiredArgumentsWork
public void RequiredArgumentsWork()
{
var strategy = new Parser();
strategy.AddDescription(new NamedArgumentDescription<string>("required") { IsRequired = true });
var actual = strategy.Parse("--notrequired=mmmm");
Assert.That(actual.IsValid, Is.False);
var actual2 = strategy.Parse("--required=aaa");
Assert.That(actual2.IsValid);
}
示例2: PatternMatchingWorks
public void PatternMatchingWorks()
{
var strategy = new Parser();
strategy.AddDescription(new NamedArgumentDescription<string>("numbers") { MatchPattern = "^\\d+$" });
var actual = strategy.Parse("--numbers=ab112d");
Assert.That(actual.IsValid, Is.False);
var actual2 = strategy.Parse("--numbers=12345");
Assert.That(actual2.IsValid);
}
示例3: PositionedArgumentValidation
public void PositionedArgumentValidation()
{
var strategy = new Parser();
strategy.AddDescription(new PositionedArgumentDescription<string>(0) { MatchPattern = "^\\d+$" });
var actual = strategy.Parse("ab112d", "111333442");
Assert.That(actual.IsValid, Is.False);
var actual2 = strategy.Parse("111333442", "ab112d");
Assert.That(actual2.IsValid);
}
示例4: TypeConversion
public void TypeConversion()
{
var parser = new Parser();
parser.AddDescription(new NamedArgumentDescription<int>("number"));
parser.AddDescription(new PositionedArgumentDescription<DateTime>(0));
var actual = parser.Parse("2010-01-01", "--number=123", "--othern=123");
Assert.That(actual.IsValid);
var positionedDate = actual.Arguments.OfType<PositionedArgument<DateTime>>().SingleOrDefault();
Assert.That(positionedDate, Is.Not.Null);
Assert.That(positionedDate.Position, Is.EqualTo(0));
Assert.That(positionedDate.Value, Is.EqualTo(new DateTime(2010, 1, 1)));
var namedInt = actual.Arguments.OfType<NamedArgument<int>>().SingleOrDefault();
Assert.That(namedInt, Is.Not.Null);
Assert.That(namedInt.Name, Is.EqualTo("number"));
Assert.That(namedInt.Value, Is.EqualTo(123));
var strings = actual.Arguments.OfType<NamedArgument<string>>();
Assert.That(strings.Count(), Is.EqualTo(1));
Assert.That(strings.Single().Name, Is.EqualTo("othern"));
}