本文整理汇总了C#中IScope.Validate方法的典型用法代码示例。如果您正苦于以下问题:C# IScope.Validate方法的具体用法?C# IScope.Validate怎么用?C# IScope.Validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IScope
的用法示例。
在下文中一共展示了IScope.Validate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Usage_Rule
static void Usage_Rule(Domain domain, IScope scope)
{
scope.Validate(domain.Property, "Property", StringIs.NotEmpty);
scope.Validate(domain.Value, "Value", Is.NotDefault);
scope.ValidateMany(domain.Properties, "Properties", StringIs.NotEmpty);
//scope.ValidateMany(domain.Values, "Values", 100, Is.NotDefault);
scope.ValidateMany(domain.Values, "Values", Is.NotDefault);
//scope.ValidateMany(domain.Values, "Values", 100, Is.NotDefault);
scope.Validate(() => domain.Property, StringIs.NotEmpty);
scope.Validate(() => domain.Value, Is.NotDefault);
// medium trust
scope.Validate(domain, d => d.Property, StringIs.NotEmpty);
scope.Validate(domain, d => d.Value, Is.NotDefault);
scope.ValidateMany(() => domain.Properties, StringIs.NotEmpty);
scope.ValidateMany(() => domain.Values, Is.NotDefault);
// medium trust
scope.ValidateMany(domain, d => d.Properties, StringIs.NotEmpty);
scope.ValidateMany(domain, d => d.Values, Is.NotDefault);
scope.ValidateInScope(domain, (domain1, scope1) => { });
scope.ValidateInScope(new[] {domain}, (domain1, scope1) => { });
}
示例2: ProgramRules
public static void ProgramRules(Program program, IScope scope)
{
// custom logic
if (!program.Active) scope.Error("Program must be active");
// passing member validation down to the next ruleset
// (note, that we have multiple rulesets here)
scope.Validate(program.Name, "Name", NameRules, SanitationRules);
}
示例3: Valid
public static void Valid(Customer customer, IScope scope)
{
scope.Validate(() => customer.Name, StringIs.Limited(3, 64));
if (customer.Address.Country == Country.Russia)
{
scope.Validate(() => customer.Email, (s, scope1) =>
{
if (!string.IsNullOrEmpty(s))
scope1.Error(
@"Russian customers do not have emails.
Use pigeons instead.");
});
}
else
{
scope.Validate(() => customer.Email, StringIs.ValidEmail);
}
}
示例4: Valid
// simple static rule
public static void Valid(Address address, IScope scope)
{
scope.Validate(() => address.Street1, StringIs.Limited(10, 256));
scope.Validate(() => address.Street2, StringIs.Limited(256));
scope.Validate(() => address.Country, Is.NotDefault);
scope.Validate(() => address.Zip, StringIs.Limited(10));
switch (address.Country)
{
case Country.USA:
scope.Validate(() => address.Zip, StringIs.Limited(5, 10));
break;
case Country.France:
break;
case Country.Russia:
scope.Validate(() => address.Zip, StringIs.Limited(6, 6));
break;
default:
scope.Validate(() => address.Zip, StringIs.Limited(1, 64));
break;
}
}
示例5: ValidateModelExpression
static void ValidateModelExpression(Model model, IScope scope)
{
scope.Validate(model, m => m.Login, StringIs.ValidEmail);
scope.Validate(model, m => m.Name, StringIs.NotEmpty);
scope.ValidateMany(model, m => m.Logins, StringIs.ValidEmail);
scope.ValidateMany(model, m => m.Names, StringIs.NotEmpty);
}
示例6: ValidateModel
static void ValidateModel(Model model, IScope scope)
{
scope.Validate(() => model.Login, StringIs.ValidEmail);
scope.Validate(() => model.Name, StringIs.NotEmpty);
}
示例7: VisitorRules
public static void VisitorRules(Visitor visitor, IScope scope)
{
// rules can validate members in the same manner
scope.Validate(visitor.Name, "Name", NameRules);
scope.Validate(visitor.Programs, "Programs", ProgramsRules);
}