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


C# JsonProperty.PropertyInfo方法代码示例

本文整理汇总了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;
        }
开发者ID:shaunparsloe,项目名称:Swashbuckle,代码行数:30,代码来源:SchemaExtensions.cs

示例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;
        }
开发者ID:andycmaj,项目名称:Ahoy,代码行数:45,代码来源:SchemaExtensions.cs


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