• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Required类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Required的典型用法代码示例。如果您正苦于以下问题:C# Required类的具体用法?C# Required怎么用?C# Required使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Required类属于命名空间,在下文中一共展示了Required类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TripField

 public TripField(string name, TripType type, long identifier, Required required)
 {
     Name = Enforce.IsNotNull<string>(name, "name");
     Type = Enforce.IsNotNull<TripType>(type, "type");
     Identifier = identifier;
     Required = required;
 }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:7,代码来源:LeanField.cs


示例2: CreateSchemaWithFormat

            private JSchema CreateSchemaWithFormat(Type type, Required required, string format)
            {
                JSchemaGenerator generator = new JSchemaGenerator();
                JSchema schema = generator.Generate(type, required != Required.Always);
                schema.Format = format;

                return schema;
            }
开发者ID:Nangal,项目名称:Newtonsoft.Json.Schema,代码行数:8,代码来源:CreateCustomProvider.cs


示例3: JSchemaTypeGenerationContext

 /// <summary>
 /// Initializes a new instance of the <see cref="JSchemaTypeGenerationContext"/> class.
 /// </summary>
 /// <param name="objectType">The object type.</param>
 /// <param name="required">The required state.</param>
 /// <param name="memberProperty">The member property.</param>
 /// <param name="parentContract">The parent contract.</param>
 /// <param name="generator">The current <see cref="JSchemaGenerator"/>.</param>
 public JSchemaTypeGenerationContext(Type objectType, Required required, JsonProperty memberProperty, JsonContainerContract parentContract, JSchemaGenerator generator)
 {
     _objectType = objectType;
     _required = required;
     _memberProperty = memberProperty;
     _parentContract = parentContract;
     _generator = generator;
 }
开发者ID:Pondidum,项目名称:Newtonsoft.Json.Schema,代码行数:16,代码来源:JSchemaTypeGenerationContext.cs


示例4: Should_fix_all_args

 public void Should_fix_all_args()
 {
     var pattern = new Required(new Argument("N"), new Argument("N"));
     Assert.AreEqual(pattern.Children[0], pattern.Children[1]);
     Assert.AreNotSame(pattern.Children[0], pattern.Children[1]);
     pattern.FixIdentities();
     Assert.AreSame(pattern.Children[0], pattern.Children[1]);
 }
开发者ID:Comandermuffif,项目名称:docopt.net,代码行数:8,代码来源:PatternFixIdentitiesTests.cs


示例5: When_Required_And_StringValue_Is_Null

        public void When_Required_And_StringValue_Is_Null()
        {
            var customer = new Customer();

            var validator = new Required<Customer, string>();
            var context = new RuleValidatorContext<Customer, string>(customer, "Name", customer.Name, null, null);

            //Validate the validator only, return true of no error returned
            var result = validator.Validate(context, null);

            Assert.IsNotEmpty(result.Message);
        }
开发者ID:TheProjecter,项目名称:specexpress,代码行数:12,代码来源:RequiredTests.cs


示例6: When_Required_And_CollectionValue_Is_Null

        public void When_Required_And_CollectionValue_Is_Null()
        {
            var customer = new Customer();

            var validator = new Required<Customer, IEnumerable>();
            var context = new RuleValidatorContext<Customer, IEnumerable>(customer, "Contacts", customer.Contacts, null, null);

            //Validate the validator only, return true of no error returned
            var result = validator.Validate(context, null);

            Assert.IsNotEmpty(result.Message);
        }
开发者ID:TheProjecter,项目名称:specexpress,代码行数:12,代码来源:RequiredTests.cs


示例7: When_Required_And_CollectionValue_Is_Empty_IsInvalid

        public void When_Required_And_CollectionValue_Is_Empty_IsInvalid()
        {
            var customer = new Customer() {Contacts = new List<Contact>()};

            var validator = new Required<Customer, IEnumerable>();
            var context = new RuleValidatorContext<Customer, IEnumerable>(customer, "Contacts", customer.Contacts, null, ValidationLevelType.Error, null);

            var notification = new ValidationNotification();

            //Validate the validator only, return true of no error returned
            validator.Validate(context, null, notification);

            Assert.IsNotEmpty(notification.Errors[0].Message);
        }
开发者ID:rbell,项目名称:SpecExpress,代码行数:14,代码来源:RequiredTests.cs


示例8: When_Required_And_StringValue_Is_Null

        public void When_Required_And_StringValue_Is_Null()
        {
            var customer = new Customer();

            var validator = new Required<Customer, string>();
            var context = new RuleValidatorContext<Customer, string>(customer, "Name", customer.Name, null, ValidationLevelType.Error, null);

            var notification = new ValidationNotification();

            //Validate the validator only, return true of no error returned
            validator.Validate(context, null, notification);

            Assert.IsNotEmpty(notification.Errors[0].Message);
        }
开发者ID:rbell,项目名称:SpecExpress,代码行数:14,代码来源:RequiredTests.cs


示例9: Generate

        public JSchema Generate(Type type, Required required)
        {
            JSchema schema = GenerateInternal(type, required, null, null);

            if (_generator.SchemaLocationHandling == SchemaLocationHandling.Definitions)
            {
                if (_typeSchemas.Count > 1)
                {
                    JToken definitions;
                    if (!schema.ExtensionData.TryGetValue("definitions", out definitions))
                    {
                        definitions = new JObject();
                        schema.ExtensionData["definitions"] = definitions;
                    }

                    foreach (TypeSchema t in _typeSchemas)
                    {
                        if (t.Schema == schema)
                        {
                            continue;
                        }

                        string id;
                        if (t.Schema.Id != null)
                        {
                            id = t.Schema.Id.OriginalString;
                        }
                        else
                        {
                            id = t.Key.Type.Name;
                            int i = 1;
                            while (definitions[id] != null)
                            {
                                id = t.Key.Type.Name + "-" + i;
                                i++;
                            }
                        }

                        definitions[id] = t.Schema;
                    }
                }
            }

            return schema;
        }
开发者ID:Pondidum,项目名称:Newtonsoft.Json.Schema,代码行数:45,代码来源:JSchemaGeneratorInternal.cs


示例10: AddNullType

        private JSchemaType AddNullType(JSchemaType type, Required valueRequired)
        {
            if (valueRequired == Required.Default || valueRequired == Required.AllowNull)
            {
                return type | JSchemaType.Null;
            }

            return type;
        }
开发者ID:Pondidum,项目名称:Newtonsoft.Json.Schema,代码行数:9,代码来源:JSchemaGeneratorInternal.cs


示例11: CreateKey

        private static TypeSchemaKey CreateKey(Required valueRequired, JsonProperty memberProperty, JsonContract contract)
        {
            int? minLength = DataAnnotationHelpers.GetMinLength(memberProperty);
            int? maxLength = DataAnnotationHelpers.GetMaxLength(memberProperty);

            Required resolvedRequired;
            switch (valueRequired)
            {
                case Required.Default:
                case Required.AllowNull:
                    resolvedRequired = Required.AllowNull;
                    break;
                case Required.Always:
                case Required.DisallowNull:
                    resolvedRequired = Required.DisallowNull;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("valueRequired");
            }

            TypeSchemaKey key = new TypeSchemaKey(contract.UnderlyingType, resolvedRequired, minLength, maxLength);

            return key;
        }
开发者ID:Pondidum,项目名称:Newtonsoft.Json.Schema,代码行数:24,代码来源:JSchemaGeneratorInternal.cs


示例12: GenerateInternal

 // Token: 0x06000B87 RID: 2951
 // RVA: 0x00042BE0 File Offset: 0x00040DE0
 private JsonSchema GenerateInternal(Type type, Required valueRequired, bool required)
 {
     ValidationUtils.ArgumentNotNull(type, "type");
     string typeId = this.GetTypeId(type, false);
     string typeId2 = this.GetTypeId(type, true);
     if (!string.IsNullOrEmpty(typeId))
     {
         JsonSchema schema = this._resolver.GetSchema(typeId);
         if (schema != null)
         {
             if (valueRequired != Required.Always && !JsonSchemaGenerator.HasFlag(schema.Type, JsonSchemaType.Null))
             {
                 schema.Type |= JsonSchemaType.Null;
             }
             if (required && schema.Required != true)
             {
                 schema.Required = new bool?(true);
             }
             return schema;
         }
     }
     if (Enumerable.Any<JsonSchemaGenerator.TypeSchema>(this._stack, (JsonSchemaGenerator.TypeSchema tc) => tc.Type == type))
     {
         throw new JsonException(StringUtils.FormatWith("Unresolved circular reference for type '{0}'. Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property.", CultureInfo.InvariantCulture, type));
     }
     JsonContract jsonContract = this.ContractResolver.ResolveContract(type);
     JsonConverter jsonConverter;
     if ((jsonConverter = jsonContract.Converter) != null || (jsonConverter = jsonContract.InternalConverter) != null)
     {
         JsonSchema schema2 = jsonConverter.GetSchema();
         if (schema2 != null)
         {
             return schema2;
         }
     }
     this.Push(new JsonSchemaGenerator.TypeSchema(type, new JsonSchema()));
     if (typeId2 != null)
     {
         this.CurrentSchema.Id = typeId2;
     }
     if (required)
     {
         this.CurrentSchema.Required = new bool?(true);
     }
     this.CurrentSchema.Title = this.GetTitle(type);
     this.CurrentSchema.Description = this.GetDescription(type);
     if (jsonConverter == null)
     {
         switch (jsonContract.ContractType)
         {
         case JsonContractType.Object:
             this.CurrentSchema.Type = new JsonSchemaType?(this.AddNullType(JsonSchemaType.Object, valueRequired));
             this.CurrentSchema.Id = this.GetTypeId(type, false);
             this.GenerateObjectSchema(type, (JsonObjectContract)jsonContract);
             goto IL_4C4;
         case JsonContractType.Array:
         {
             this.CurrentSchema.Type = new JsonSchemaType?(this.AddNullType(JsonSchemaType.Array, valueRequired));
             this.CurrentSchema.Id = this.GetTypeId(type, false);
             JsonArrayAttribute cachedAttribute = JsonTypeReflector.GetCachedAttribute<JsonArrayAttribute>(type);
             bool flag = cachedAttribute == null || cachedAttribute.AllowNullItems;
             Type collectionItemType = ReflectionUtils.GetCollectionItemType(type);
             if (collectionItemType != null)
             {
                 this.CurrentSchema.Items = new List<JsonSchema>();
                 this.CurrentSchema.Items.Add(this.GenerateInternal(collectionItemType, (!flag) ? Required.Always : Required.Default, false));
                 goto IL_4C4;
             }
             goto IL_4C4;
         }
         case JsonContractType.Primitive:
         {
             this.CurrentSchema.Type = new JsonSchemaType?(this.GetJsonSchemaType(type, valueRequired));
             if (!(this.CurrentSchema.Type == JsonSchemaType.Integer) || !TypeExtensions.IsEnum(type) || type.IsDefined(typeof(FlagsAttribute), true))
             {
                 goto IL_4C4;
             }
             this.CurrentSchema.Enum = new List<JToken>();
             IList<EnumValue<long>> namesAndValues = EnumUtils.GetNamesAndValues<long>(type);
             using (IEnumerator<EnumValue<long>> enumerator = namesAndValues.GetEnumerator())
             {
                 while (enumerator.MoveNext())
                 {
                     EnumValue<long> current = enumerator.Current;
                     JToken item = JToken.FromObject(current.Value);
                     this.CurrentSchema.Enum.Add(item);
                 }
                 goto IL_4C4;
             }
             break;
         }
         case JsonContractType.String:
             break;
         case JsonContractType.Dictionary:
         {
             this.CurrentSchema.Type = new JsonSchemaType?(this.AddNullType(JsonSchemaType.Object, valueRequired));
             Type type2;
             Type type3;
//.........这里部分代码省略.........
开发者ID:newchild,项目名称:Project-DayZero,代码行数:101,代码来源:JsonSchemaGenerator.cs


示例13: GetJsonSchemaType

    private JsonSchemaType GetJsonSchemaType(Type type, Required valueRequired)
    {
      JsonSchemaType schemaType = JsonSchemaType.None;
      if (valueRequired != Required.Always && ReflectionUtils.IsNullable(type))
      {
        schemaType = JsonSchemaType.Null;
        if (ReflectionUtils.IsNullableType(type))
          type = Nullable.GetUnderlyingType(type);
      }

      TypeCode typeCode = Type.GetTypeCode(type);

      switch (typeCode)
      {
        case TypeCode.Empty:
        case TypeCode.Object:
          return schemaType | JsonSchemaType.String;
        case TypeCode.DBNull:
          return schemaType | JsonSchemaType.Null;
        case TypeCode.Boolean:
          return schemaType | JsonSchemaType.Boolean;
        case TypeCode.Char:
          return schemaType | JsonSchemaType.String;
        case TypeCode.SByte:
        case TypeCode.Byte:
        case TypeCode.Int16:
        case TypeCode.UInt16:
        case TypeCode.Int32:
        case TypeCode.UInt32:
        case TypeCode.Int64:
        case TypeCode.UInt64:
          return schemaType | JsonSchemaType.Integer;
        case TypeCode.Single:
        case TypeCode.Double:
        case TypeCode.Decimal:
          return schemaType | JsonSchemaType.Float;
        // convert to string?
        case TypeCode.DateTime:
          return schemaType | JsonSchemaType.String;
        case TypeCode.String:
          return schemaType | JsonSchemaType.String;
        default:
          throw new Exception("Unexpected type code '{0}' for type '{1}'.".FormatWith(CultureInfo.InvariantCulture, typeCode, type));
      }
    }
开发者ID:AshD,项目名称:Newtonsoft.Json,代码行数:45,代码来源:JsonSchemaGenerator.cs


示例14: GetJsonSchemaType

        private JsonSchemaType GetJsonSchemaType(Type type, Required valueRequired)
        {
            JsonSchemaType schemaType = JsonSchemaType.None;
            if (valueRequired != Required.Always && ReflectionUtils.IsNullable(type))
            {
                schemaType = JsonSchemaType.Null;
                if (ReflectionUtils.IsNullableType(type))
                    type = Nullable.GetUnderlyingType(type);
            }

            PrimitiveTypeCode typeCode = ConvertUtils.GetTypeCode(type);

            switch (typeCode)
            {
                case PrimitiveTypeCode.Empty:
                case PrimitiveTypeCode.Object:
                    return schemaType | JsonSchemaType.String;
#if !(NETFX_CORE || PORTABLE)
                case PrimitiveTypeCode.DBNull:
                    return schemaType | JsonSchemaType.Null;
#endif
                case PrimitiveTypeCode.Boolean:
                    return schemaType | JsonSchemaType.Boolean;
                case PrimitiveTypeCode.Char:
                    return schemaType | JsonSchemaType.String;
                case PrimitiveTypeCode.SByte:
                case PrimitiveTypeCode.Byte:
                case PrimitiveTypeCode.Int16:
                case PrimitiveTypeCode.UInt16:
                case PrimitiveTypeCode.Int32:
                case PrimitiveTypeCode.UInt32:
                case PrimitiveTypeCode.Int64:
                case PrimitiveTypeCode.UInt64:
#if !(PORTABLE || NET35 || NET20)
                case PrimitiveTypeCode.BigInteger:
#endif
                    return schemaType | JsonSchemaType.Integer;
                case PrimitiveTypeCode.Single:
                case PrimitiveTypeCode.Double:
                case PrimitiveTypeCode.Decimal:
                    return schemaType | JsonSchemaType.Float;
                    // convert to string?
                case PrimitiveTypeCode.DateTime:
#if !NET20
                case PrimitiveTypeCode.DateTimeOffset:
#endif
                    return schemaType | JsonSchemaType.String;
                case PrimitiveTypeCode.String:
                case PrimitiveTypeCode.Uri:
                case PrimitiveTypeCode.Guid:
                case PrimitiveTypeCode.TimeSpan:
                case PrimitiveTypeCode.Bytes:
                    return schemaType | JsonSchemaType.String;
                default:
                    throw new JsonException("Unexpected type code '{0}' for type '{1}'.".FormatWith(CultureInfo.InvariantCulture, typeCode, type));
            }
        }
开发者ID:GOArango,项目名称:arangoclient.net,代码行数:57,代码来源:JsonSchemaGenerator.cs


示例15: ConsoleHelpAttribute

 public ConsoleHelpAttribute(string helpText,Required requiredType = Required.NotReuired)
 {
     HelpText = helpText;
     RequiredType = requiredType;
 }
开发者ID:reinforced,项目名称:Reinforced.Typings,代码行数:5,代码来源:ConsoleHelpAttribute.cs


示例16: Insert

 public void Insert(Required required)
 {
     DbContext.Requireds.Add(required);
     Update();
 }
开发者ID:xiaoxiao95888,项目名称:OA_Game,代码行数:5,代码来源:RequiredService.cs


示例17: AddNullType

        private JsonSchemaType AddNullType(JsonSchemaType type, Required valueRequired)
        {
            if (valueRequired != Required.Always)
            {
                return type | JsonSchemaType.Null;
            }

            return type;
        }
开发者ID:Dylan-Jang,项目名称:Newtonsoft.Json,代码行数:9,代码来源:JsonSchemaGenerator.cs


示例18: GenerateInternal

        private JsonSchema GenerateInternal(Type type, Required valueRequired)
        {
            ValidationUtils.ArgumentNotNull(type, "type");

              string resolvedId = GetTypeId(type, false);
              string explicitId = GetTypeId(type, true);

              if (!string.IsNullOrEmpty(resolvedId))
              {
            JsonSchema resolvedSchema = _resolver.GetSchema(resolvedId);
            if (resolvedSchema != null)
              return resolvedSchema;
              }

              // test for unresolved circular reference
              if (_stack.Any(tc => tc.Type == type))
              {
            throw new Exception("Unresolved circular reference for type '{0}'. Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property.".FormatWith(CultureInfo.InvariantCulture, type));
              }

              Push(new TypeSchema(type, new JsonSchema()));

              if (explicitId != null)
            CurrentSchema.Id = explicitId;

              CurrentSchema.Title = GetTitle(type);
              CurrentSchema.Description = GetDescription(type);

              if (CollectionUtils.IsDictionaryType(type))
              {
            // TODO: include null
            CurrentSchema.Type = JsonSchemaType.Object;

            Type keyType;
            Type valueType;
            ReflectionUtils.GetDictionaryKeyValueTypes(type, out keyType, out valueType);

            if (keyType != null)
            {
              // can be converted to a string
              if (typeof (IConvertible).IsAssignableFrom(keyType))
              {
            CurrentSchema.AdditionalProperties = GenerateInternal(valueType, Required.Default);
              }
            }
              }
              else if (CollectionUtils.IsCollectionType(type))
              {
            // TODO: include null
            CurrentSchema.Type = JsonSchemaType.Array;

            CurrentSchema.Id = GetTypeId(type, false);

            JsonArrayAttribute arrayAttribute = JsonTypeReflector.GetJsonContainerAttribute(type) as JsonArrayAttribute;
            bool allowNullItem = (arrayAttribute != null) ? arrayAttribute.AllowNullItems : false;

            Type collectionItemType = ReflectionUtils.GetCollectionItemType(type);
            if (collectionItemType != null)
            {
              CurrentSchema.Items = new List<JsonSchema>();
              CurrentSchema.Items.Add(GenerateInternal(collectionItemType, (!allowNullItem) ? Required.Always : Required.Default));
            }
              }
              else
              {
            CurrentSchema.Type = GetJsonSchemaType(type, valueRequired);

            if (HasFlag(CurrentSchema.Type, JsonSchemaType.Object))
            {
              CurrentSchema.Id = GetTypeId(type, false);

              JsonObjectContract contract = ContractResolver.ResolveContract(type) as JsonObjectContract;

              if (contract == null)
            throw new Exception("Could not resolve contract for '{0}'.".FormatWith(CultureInfo.InvariantCulture, type));

              CurrentSchema.Properties = new Dictionary<string, JsonSchema>();
              foreach (JsonProperty property in contract.Properties)
              {
            if (!property.Ignored)
            {
              JsonSchema propertySchema = GenerateInternal(property.PropertyType, property.Required);

              if (property.DefaultValue != null)
                propertySchema.Default = JToken.FromObject(property.DefaultValue);

              CurrentSchema.Properties.Add(property.PropertyName, propertySchema);
            }
              }

              if (type.IsSealed)
            CurrentSchema.AllowAdditionalProperties = false;
            }
            else if (CurrentSchema.Type == JsonSchemaType.Integer && type.IsEnum && !type.IsDefined(typeof(FlagsAttribute), true))
            {
              CurrentSchema.Enum = new List<JToken>();
              CurrentSchema.Options = new Dictionary<JToken, string>();

              EnumValues<long> enumValues = EnumUtils.GetNamesAndValues<long>(type);
              foreach (EnumValue<long> enumValue in enumValues)
//.........这里部分代码省略.........
开发者ID:anukat2015,项目名称:sones,代码行数:101,代码来源:JsonSchemaGenerator.cs


示例19: CreateKey

        private static TypeSchemaKey CreateKey(Required valueRequired, JsonProperty memberProperty, JsonContract contract)
        {
            int? minLength = DataAnnotationHelpers.GetMinLength(memberProperty);
            int? maxLength = DataAnnotationHelpers.GetMaxLength(memberProperty);

            TypeSchemaKey key = new TypeSchemaKey(contract.UnderlyingType, valueRequired, minLength, maxLength);
            return key;
        }
开发者ID:rynnwang,项目名称:Newtonsoft.Json.Schema,代码行数:8,代码来源:JSchemaGenerator.cs


示例20: GenerateInternal

    private JsonSchema GenerateInternal(Type type, Required valueRequired, bool required)
    {
      ValidationUtils.ArgumentNotNull(type, "type");

      string resolvedId = GetTypeId(type, false);
      string explicitId = GetTypeId(type, true);

      if (!string.IsNullOrEmpty(resolvedId))
      {
        JsonSchema resolvedSchema = _resolver.GetSchema(resolvedId);
        if (resolvedSchema != null)
        {
          // resolved schema is not null but referencing member allows nulls
          // change resolved schema to allow nulls. hacky but what are ya gonna do?
          if (valueRequired != Required.Always && !HasFlag(resolvedSchema.Type, JsonSchemaType.Null))
            resolvedSchema.Type |= JsonSchemaType.Null;
          if (required && resolvedSchema.Required != true)
            resolvedSchema.Required = true;

          return resolvedSchema;
        }
      }

      // test for unresolved circular reference
      if (_stack.Any(tc => tc.Type == type))
      {
        throw new Exception("Unresolved circular reference for type '{0}'. Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property.".FormatWith(CultureInfo.InvariantCulture, type));
      }

      JsonContract contract = ContractResolver.ResolveContract(type);
      JsonConverter converter;
      if ((converter = contract.Converter) != null || (converter = contract.InternalConverter) != null)
      {
        JsonSchema converterSchema = converter.GetSchema();
        if (converterSchema != null)
          return converterSchema;
      }

      Push(new TypeSchema(type, new JsonSchema()));

      if (explicitId != null)
        CurrentSchema.Id = explicitId;

      if (required)
        CurrentSchema.Required = true;
      CurrentSchema.Title = GetTitle(type);
      CurrentSchema.Description = GetDescription(type);

      if (converter != null)
      {
        // todo: Add GetSchema to JsonConverter and use here?
        CurrentSchema.Type = JsonSchemaType.Any;
      }
      else
      {
        switch (contract.ContractType)
        {
          case JsonContractType.Object:
            CurrentSchema.Type = AddNullType(JsonSchemaType.Object, valueRequired);
            CurrentSchema.Id = GetTypeId(type, false);
            GenerateObjectSchema(type, (JsonObjectContract) contract);
            break;
          case JsonContractType.Array:
            CurrentSchema.Type = AddNullType(JsonSchemaType.Array, valueRequired);

            CurrentSchema.Id = GetTypeId(type, false);

            JsonArrayAttribute arrayAttribute = JsonTypeReflector.GetJsonContainerAttribute(type) as JsonArrayAttribute;
            bool allowNullItem = (arrayAttribute == null || arrayAttribute.AllowNullItems);

            Type collectionItemType = ReflectionUtils.GetCollectionItemType(type);
            if (collectionItemType != null)
            {
              CurrentSchema.Items = new List<JsonSchema>();
              CurrentSchema.Items.Add(GenerateInternal(collectionItemType, (!allowNullItem) ? Required.Always : Required.Default, false));
            }
            break;
          case JsonContractType.Primitive:
            CurrentSchema.Type = GetJsonSchemaType(type, valueRequired);

            if (CurrentSchema.Type == JsonSchemaType.Integer && type.IsEnum && !type.IsDefined(typeof (FlagsAttribute), true))
            {
              CurrentSchema.Enum = new List<JToken>();
              CurrentSchema.Options = new Dictionary<JToken, string>();

              EnumValues<long> enumValues = EnumUtils.GetNamesAndValues<long>(type);
              foreach (EnumValue<long> enumValue in enumValues)
              {
                JToken value = JToken.FromObject(enumValue.Value);

                CurrentSchema.Enum.Add(value);
                CurrentSchema.Options.Add(value, enumValue.Name);
              }
            }
            break;
          case JsonContractType.String:
            JsonSchemaType schemaType = (!ReflectionUtils.IsNullable(contract.UnderlyingType))
                                          ? JsonSchemaType.String
                                          : AddNullType(JsonSchemaType.String, valueRequired);

//.........这里部分代码省略.........
开发者ID:AshD,项目名称:Newtonsoft.Json,代码行数:101,代码来源:JsonSchemaGenerator.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# RequiredMessageHeader类代码示例发布时间:2022-05-24
下一篇:
C# RequestType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap