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


C# JsonObject.ValidateStringLength方法代码示例

本文整理汇总了C#中System.Json.JsonObject.ValidateStringLength方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.ValidateStringLength方法的具体用法?C# JsonObject.ValidateStringLength怎么用?C# JsonObject.ValidateStringLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Json.JsonObject的用法示例。


在下文中一共展示了JsonObject.ValidateStringLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Post

        public JsonObject Post(JsonObject contact)
        {
            if (contact == null)
            {
                throw new ArgumentNullException("contact");
            }

            contact.ValidateStringLength("What", 1, MaxFieldLength)
                   .ValidateCustomValidator("StartDate", typeof(CustomValidator), "ValidateMeetingTime")
                   .ValidateStringLength("Where", 1, MaxFieldLength)
                   .ValidateStringLength("Description", MaxFieldLength)
                   .ValidateCustomValidator("ReminderValue", typeof(CustomValidator), "ValidateReminder")
                   .ValidateEnum("ShowMeAs", typeof(ShowMeAs))
                   .ValidateCustomValidator("Guests", typeof(CustomValidator), "ValidateGuestEmails");

            string modifyEventName = "ModifyEvent";
            if (contact.ContainsKey(modifyEventName))
            {
                contact.ValidateTypeOf<bool>(modifyEventName);
            }

            string inviteOthersName = "InviteOthers";
            if (contact.ContainsKey(inviteOthersName))
            {
                contact.ValidateTypeOf<bool>(inviteOthersName);
            }

            string seeGuestListName = "SeeGuestList";
            if (contact.ContainsKey(seeGuestListName))
            {
                contact.ValidateTypeOf<bool>(seeGuestListName);
            }

            return new JsonObject();
        }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:35,代码来源:CalendarResource.cs

示例2: ValidationAPITest

        public void ValidationAPITest()
        {
            JsonObject jo = new JsonObject();
            jo.Add("date", new DateTime(2000, 1, 1, 0, 0, 0));
            jo.Add("int", 1);
            jo.Add("double", 1.1);
            jo.Add("string", "12CharString");
            jo.Add("enum", "Number");

            jo.ValidatePresence("date")
              .ValidateEnum("enum", typeof(JsonType))
              .ValidateRange("double", 0.1, 1.2)
              .ValidateRange("int", 0, 2)
              .ValidateRange<DateTime>("date", DateTime.MinValue, DateTime.MaxValue)
              .ValidateRegularExpression("int", "^.+$")
              .ValidateStringLength("string", 15)
              .ValidateStringLength("string", 0, 15)
              .ValidateTypeOf<double>("int")
              .ValidateCustomValidator("string", typeof(MyCustomValidationClass), "IsStringContainsCharSimple")
              .ValidateCustomValidator("string", typeof(MyCustomValidationClass), "IsStringContainsCharComplex");

            ExceptionTestHelper.ExpectException<ValidationException>(delegate { jo.ValidatePresence("invalidkey"); });
            ExceptionTestHelper.ExpectException<ValidationException>(delegate { jo.ValidateEnum("date", typeof(JsonType)); });
            ExceptionTestHelper.ExpectException<ValidationException>(delegate { jo.ValidateRange("double", 2.2, 3.2); });
            ExceptionTestHelper.ExpectException<ValidationException>(delegate { jo.ValidateRange("int", 2, 3); });
            ExceptionTestHelper.ExpectException<ValidationException>(delegate { jo.ValidateRange<DateTime>("date", DateTime.MaxValue, DateTime.MaxValue); });
            ExceptionTestHelper.ExpectException<ValidationException>(delegate { jo.ValidateRegularExpression("string", "doesnotmatch"); });
            ExceptionTestHelper.ExpectException<ValidationException>(delegate { jo.ValidateStringLength("string", 10); });
            ExceptionTestHelper.ExpectException<ValidationException>(delegate { jo.ValidateStringLength("string", 15, 25); });
            ExceptionTestHelper.ExpectException<ValidationException>(delegate { jo.ValidateTypeOf<double>("date"); });
            ExceptionTestHelper.ExpectException<ValidationException>(delegate { jo.ValidateCustomValidator("enum", typeof(MyCustomValidationClass), "IsStringContainsCharSimple"); });
            ExceptionTestHelper.ExpectException<ValidationException>(delegate { jo.ValidateCustomValidator("enum", typeof(MyCustomValidationClass), "IsStringContainsCharComplex"); });
        }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:33,代码来源:JsonObjectTest.cs


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