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


C# Required类代码示例

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


Required类属于命名空间,在下文中一共展示了Required类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ConsoleHelpAttribute

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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例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);
      }

      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

示例15: 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


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