本文整理汇总了C#中Newtonsoft.Json.Serialization.JsonProperty.PropertyInfo方法的典型用法代码示例。如果您正苦于以下问题:C# JsonProperty.PropertyInfo方法的具体用法?C# JsonProperty.PropertyInfo怎么用?C# JsonProperty.PropertyInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Serialization.JsonProperty
的用法示例。
在下文中一共展示了JsonProperty.PropertyInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WithValidationProperties
public static Schema WithValidationProperties(this Schema schema, JsonProperty jsonProperty)
{
var propInfo = jsonProperty.PropertyInfo();
if (propInfo == null)
return schema;
foreach (var attribute in propInfo.GetCustomAttributes(false))
{
var regex = attribute as RegularExpressionAttribute;
if (regex != null)
schema.pattern = regex.Pattern;
var range = attribute as RangeAttribute;
if (range != null)
{
int maximum;
if (Int32.TryParse(range.Maximum.ToString(), out maximum))
schema.maximum = maximum;
int minimum;
if (Int32.TryParse(range.Minimum.ToString(), out minimum))
schema.minimum = minimum;
}
}
if (!jsonProperty.Writable)
schema.readOnly = true;
return schema;
}
示例2: AssignValidationProperties
public static Schema AssignValidationProperties(this Schema schema, JsonProperty jsonProperty)
{
var propInfo = jsonProperty.PropertyInfo();
if (propInfo == null)
return schema;
foreach (var attribute in propInfo.GetCustomAttributes(false))
{
var regex = attribute as RegularExpressionAttribute;
if (regex != null)
schema.Pattern = regex.Pattern;
var range = attribute as RangeAttribute;
if (range != null)
{
int maximum;
if (Int32.TryParse(range.Maximum.ToString(), out maximum))
schema.Maximum = maximum;
int minimum;
if (Int32.TryParse(range.Minimum.ToString(), out minimum))
schema.Minimum = minimum;
}
var minLength = attribute as MinLengthAttribute;
if (minLength != null)
schema.MinLength = minLength.Length;
var maxLength = attribute as MaxLengthAttribute;
if (maxLength != null)
schema.MaxLength = maxLength.Length;
var stringLength = attribute as StringLengthAttribute;
if (stringLength != null)
{
schema.MinLength = stringLength.MinimumLength;
schema.MaxLength = stringLength.MaximumLength;
}
}
if (!jsonProperty.Writable)
schema.ReadOnly = true;
return schema;
}