当前位置: 首页>>代码示例>>C#>>正文


C# IScope.Validate方法代码示例

本文整理汇总了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) => { });
        }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:28,代码来源:RuleExtensionsTests.cs

示例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);
 }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:8,代码来源:BusinessRules.cs

示例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);
            }
        }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:19,代码来源:CustomerIs.cs

示例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;
            }
        }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:23,代码来源:AddressIs.cs

示例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);
 }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:7,代码来源:ExtendIScopeForMediumTrustTests.cs

示例6: ValidateModel

 static void ValidateModel(Model model, IScope scope)
 {
     scope.Validate(() => model.Login, StringIs.ValidEmail);
     scope.Validate(() => model.Name, StringIs.NotEmpty);
 }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:5,代码来源:ExtendIScopeForMediumTrustTests.cs

示例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);
 }
开发者ID:pocheptsov,项目名称:lokad-shared-libraries,代码行数:6,代码来源:BusinessRules.cs


注:本文中的IScope.Validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。