本文整理汇总了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();
}
示例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"); });
}