示例#1
0
        /// <summary>
        /// Skips the children of the current token.
        /// </summary>
        public void Skip()
        {
            if (TokenType == JsonToken.PropertyName)
            {
                Read();
            }

            if (JsonTokenUtils.IsStartToken(TokenType))
            {
                int depth = Depth;

                while (Read() && (depth < Depth))
                {
                }
            }
        }
        /// <summary>
        /// Asynchronously skips the children of the current token.
        /// </summary>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
        /// <remarks>The default behaviour is to execute synchronously, returning an already-completed task. Derived
        /// classes can override this behaviour for true asynchronicity.</remarks>
        public async Task SkipAsync(CancellationToken cancellationToken = default)
        {
            if (TokenType == JsonToken.PropertyName)
            {
                await ReadAsync(cancellationToken).ConfigureAwait(false);
            }

            if (JsonTokenUtils.IsStartToken(TokenType))
            {
                int depth = Depth;

                while (await ReadAsync(cancellationToken).ConfigureAwait(false) && depth < Depth)
                {
                }
            }
        }
示例#3
0
        public void Skip()
        {
            if (this.TokenType == JsonToken.PropertyName)
            {
                this.Read();
            }
            if (!JsonTokenUtils.IsStartToken(this.TokenType))
            {
                return;
            }
            int depth = this.Depth;

            do
            {
                ;
            }while (this.Read() && depth < this.Depth);
        }
示例#4
0
        public async Task SkipAsync(CancellationToken cancellationToken = null)
        {
            ConfiguredTaskAwaitable <bool> configuredTaskAwaitable;

            if (this.TokenType == JsonToken.PropertyName)
            {
                configuredTaskAwaitable = this.ReadAsync(cancellationToken).ConfigureAwait(false);
                await configuredTaskAwaitable;
            }
            if (JsonTokenUtils.IsStartToken(this.TokenType))
            {
                int depth = this.Depth;
                do
                {
                    configuredTaskAwaitable = this.ReadAsync(cancellationToken).ConfigureAwait(false);
                }while (await configuredTaskAwaitable && depth < this.Depth);
            }
        }
        private void ValidateCurrentToken()
        {
            // first time validate has been called. build model
            if (_model == null)
            {
                JsonSchemaModelBuilder builder = new JsonSchemaModelBuilder();
                _model = builder.Build(_schema);

                if (!JsonTokenUtils.IsStartToken(_reader.TokenType))
                {
                    Push(new SchemaScope(JTokenType.None, CurrentMemberSchemas));
                }
            }

            switch (_reader.TokenType)
            {
            case JsonToken.StartObject:
                ProcessValue();
                IList <JsonSchemaModel> objectSchemas = CurrentMemberSchemas.Where(ValidateObject).ToList();
                Push(new SchemaScope(JTokenType.Object, objectSchemas));
                WriteToken(CurrentSchemas);
                break;

            case JsonToken.StartArray:
                ProcessValue();
                IList <JsonSchemaModel> arraySchemas = CurrentMemberSchemas.Where(ValidateArray).ToList();
                Push(new SchemaScope(JTokenType.Array, arraySchemas));
                WriteToken(CurrentSchemas);
                break;

            case JsonToken.StartConstructor:
                ProcessValue();
                Push(new SchemaScope(JTokenType.Constructor, null));
                WriteToken(CurrentSchemas);
                break;

            case JsonToken.PropertyName:
                WriteToken(CurrentSchemas);
                foreach (JsonSchemaModel schema in CurrentSchemas)
                {
                    ValidatePropertyName(schema);
                }
                break;

            case JsonToken.Raw:
                ProcessValue();
                break;

            case JsonToken.Integer:
                ProcessValue();
                WriteToken(CurrentMemberSchemas);
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateInteger(schema);
                }
                break;

            case JsonToken.Float:
                ProcessValue();
                WriteToken(CurrentMemberSchemas);
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateFloat(schema);
                }
                break;

            case JsonToken.String:
                ProcessValue();
                WriteToken(CurrentMemberSchemas);
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateString(schema);
                }
                break;

            case JsonToken.Boolean:
                ProcessValue();
                WriteToken(CurrentMemberSchemas);
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateBoolean(schema);
                }
                break;

            case JsonToken.Null:
                ProcessValue();
                WriteToken(CurrentMemberSchemas);
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateNull(schema);
                }
                break;

            case JsonToken.EndObject:
                WriteToken(CurrentSchemas);
                foreach (JsonSchemaModel schema in CurrentSchemas)
                {
                    ValidateEndObject(schema);
                }
                Pop();
                break;

            case JsonToken.EndArray:
                WriteToken(CurrentSchemas);
                foreach (JsonSchemaModel schema in CurrentSchemas)
                {
                    ValidateEndArray(schema);
                }
                Pop();
                break;

            case JsonToken.EndConstructor:
                WriteToken(CurrentSchemas);
                Pop();
                break;

            case JsonToken.Undefined:
            case JsonToken.Date:
            case JsonToken.Bytes:
                // these have no equivalent in JSON schema
                WriteToken(CurrentMemberSchemas);
                break;

            case JsonToken.None:
                // no content, do nothing
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#6
0
        private void ValidateCurrentToken()
        {
            if (this._model == null)
            {
                this._model = new JsonSchemaModelBuilder().Build(this._schema);
                if (!JsonTokenUtils.IsStartToken(this._reader.TokenType))
                {
                    this.Push(new JsonValidatingReader.SchemaScope(JTokenType.None, this.CurrentMemberSchemas));
                }
            }

            switch (this._reader.TokenType)
            {
            case JsonToken.None:
                break;

            case JsonToken.StartObject:
                this.ProcessValue();
                this.Push(new JsonValidatingReader.SchemaScope(JTokenType.Object,
                                                               (IList <JsonSchemaModel>) this.CurrentMemberSchemas
                                                               .Where <JsonSchemaModel>(new Func <JsonSchemaModel, bool>(this.ValidateObject)).ToList <JsonSchemaModel>()));
                this.WriteToken(this.CurrentSchemas);
                break;

            case JsonToken.StartArray:
                this.ProcessValue();
                this.Push(new JsonValidatingReader.SchemaScope(JTokenType.Array,
                                                               (IList <JsonSchemaModel>) this.CurrentMemberSchemas
                                                               .Where <JsonSchemaModel>(new Func <JsonSchemaModel, bool>(this.ValidateArray)).ToList <JsonSchemaModel>()));
                this.WriteToken(this.CurrentSchemas);
                break;

            case JsonToken.StartConstructor:
                this.ProcessValue();
                this.Push(new JsonValidatingReader.SchemaScope(JTokenType.Constructor, (IList <JsonSchemaModel>)null));
                this.WriteToken(this.CurrentSchemas);
                break;

            case JsonToken.PropertyName:
                this.WriteToken(this.CurrentSchemas);
                using (IEnumerator <JsonSchemaModel> enumerator = this.CurrentSchemas.GetEnumerator()) {
                    while (enumerator.MoveNext())
                    {
                        this.ValidatePropertyName(enumerator.Current);
                    }
                    break;
                }

            case JsonToken.Raw:
                this.ProcessValue();
                break;

            case JsonToken.Integer:
                this.ProcessValue();
                this.WriteToken(this.CurrentMemberSchemas);
                using (IEnumerator <JsonSchemaModel> enumerator = this.CurrentMemberSchemas.GetEnumerator()) {
                    while (enumerator.MoveNext())
                    {
                        this.ValidateInteger(enumerator.Current);
                    }
                    break;
                }

            case JsonToken.Float:
                this.ProcessValue();
                this.WriteToken(this.CurrentMemberSchemas);
                using (IEnumerator <JsonSchemaModel> enumerator = this.CurrentMemberSchemas.GetEnumerator()) {
                    while (enumerator.MoveNext())
                    {
                        this.ValidateFloat(enumerator.Current);
                    }
                    break;
                }

            case JsonToken.String:
                this.ProcessValue();
                this.WriteToken(this.CurrentMemberSchemas);
                using (IEnumerator <JsonSchemaModel> enumerator = this.CurrentMemberSchemas.GetEnumerator()) {
                    while (enumerator.MoveNext())
                    {
                        this.ValidateString(enumerator.Current);
                    }
                    break;
                }

            case JsonToken.Boolean:
                this.ProcessValue();
                this.WriteToken(this.CurrentMemberSchemas);
                using (IEnumerator <JsonSchemaModel> enumerator = this.CurrentMemberSchemas.GetEnumerator()) {
                    while (enumerator.MoveNext())
                    {
                        this.ValidateBoolean(enumerator.Current);
                    }
                    break;
                }

            case JsonToken.Null:
                this.ProcessValue();
                this.WriteToken(this.CurrentMemberSchemas);
                using (IEnumerator <JsonSchemaModel> enumerator = this.CurrentMemberSchemas.GetEnumerator()) {
                    while (enumerator.MoveNext())
                    {
                        this.ValidateNull(enumerator.Current);
                    }
                    break;
                }

            case JsonToken.Undefined:
            case JsonToken.Date:
            case JsonToken.Bytes:
                this.WriteToken(this.CurrentMemberSchemas);
                break;

            case JsonToken.EndObject:
                this.WriteToken(this.CurrentSchemas);
                foreach (JsonSchemaModel currentSchema in (IEnumerable <JsonSchemaModel>) this.CurrentSchemas)
                {
                    this.ValidateEndObject(currentSchema);
                }
                this.Pop();
                break;

            case JsonToken.EndArray:
                this.WriteToken(this.CurrentSchemas);
                foreach (JsonSchemaModel currentSchema in (IEnumerable <JsonSchemaModel>) this.CurrentSchemas)
                {
                    this.ValidateEndArray(currentSchema);
                }
                this.Pop();
                break;

            case JsonToken.EndConstructor:
                this.WriteToken(this.CurrentSchemas);
                this.Pop();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#7
0
        private void ValidateCurrentToken()
        {
            if (this._model == null)
            {
                this._model = new JsonSchemaModelBuilder().Build(this._schema);
                if (!JsonTokenUtils.IsStartToken(this._reader.TokenType))
                {
                    this.Push(new SchemaScope(JTokenType.None, this.CurrentMemberSchemas));
                }
            }
            switch (this._reader.TokenType)
            {
            case JsonToken.None:
                return;

            case JsonToken.StartObject:
            {
                this.ProcessValue();
                IList <JsonSchemaModel> schemas = this.CurrentMemberSchemas.Where <JsonSchemaModel>(new Func <JsonSchemaModel, bool>(this.ValidateObject)).ToList <JsonSchemaModel>();
                this.Push(new SchemaScope(JTokenType.Object, schemas));
                this.WriteToken(this.CurrentSchemas);
                return;
            }

            case JsonToken.StartArray:
            {
                this.ProcessValue();
                IList <JsonSchemaModel> schemas = this.CurrentMemberSchemas.Where <JsonSchemaModel>(new Func <JsonSchemaModel, bool>(this.ValidateArray)).ToList <JsonSchemaModel>();
                this.Push(new SchemaScope(JTokenType.Array, schemas));
                this.WriteToken(this.CurrentSchemas);
                return;
            }

            case JsonToken.StartConstructor:
                this.ProcessValue();
                this.Push(new SchemaScope(JTokenType.Constructor, null));
                this.WriteToken(this.CurrentSchemas);
                return;

            case JsonToken.PropertyName:
                this.WriteToken(this.CurrentSchemas);
                foreach (JsonSchemaModel model in this.CurrentSchemas)
                {
                    this.ValidatePropertyName(model);
                }
                return;

            case JsonToken.Raw:
                this.ProcessValue();
                return;

            case JsonToken.Integer:
                this.ProcessValue();
                this.WriteToken(this.CurrentMemberSchemas);
                foreach (JsonSchemaModel model2 in this.CurrentMemberSchemas)
                {
                    this.ValidateInteger(model2);
                }
                return;

            case JsonToken.Float:
                this.ProcessValue();
                this.WriteToken(this.CurrentMemberSchemas);
                foreach (JsonSchemaModel model3 in this.CurrentMemberSchemas)
                {
                    this.ValidateFloat(model3);
                }
                return;

            case JsonToken.String:
                this.ProcessValue();
                this.WriteToken(this.CurrentMemberSchemas);
                foreach (JsonSchemaModel model4 in this.CurrentMemberSchemas)
                {
                    this.ValidateString(model4);
                }
                return;

            case JsonToken.Boolean:
                this.ProcessValue();
                this.WriteToken(this.CurrentMemberSchemas);
                foreach (JsonSchemaModel model5 in this.CurrentMemberSchemas)
                {
                    this.ValidateBoolean(model5);
                }
                return;

            case JsonToken.Null:
                this.ProcessValue();
                this.WriteToken(this.CurrentMemberSchemas);
                foreach (JsonSchemaModel model6 in this.CurrentMemberSchemas)
                {
                    this.ValidateNull(model6);
                }
                return;

            case JsonToken.Undefined:
            case JsonToken.Date:
            case JsonToken.Bytes:
                this.WriteToken(this.CurrentMemberSchemas);
                return;

            case JsonToken.EndObject:
                this.WriteToken(this.CurrentSchemas);
                foreach (JsonSchemaModel model7 in this.CurrentSchemas)
                {
                    this.ValidateEndObject(model7);
                }
                this.Pop();
                return;

            case JsonToken.EndArray:
                this.WriteToken(this.CurrentSchemas);
                foreach (JsonSchemaModel model8 in this.CurrentSchemas)
                {
                    this.ValidateEndArray(model8);
                }
                this.Pop();
                return;

            case JsonToken.EndConstructor:
                this.WriteToken(this.CurrentSchemas);
                this.Pop();
                return;
            }
            throw new ArgumentOutOfRangeException();
        }
示例#8
0
        // Token: 0x06000D88 RID: 3464 RVA: 0x00054628 File Offset: 0x00052828
        private void ValidateCurrentToken()
        {
            if (this._model == null)
            {
                JsonSchemaModelBuilder jsonSchemaModelBuilder = new JsonSchemaModelBuilder();
                this._model = jsonSchemaModelBuilder.Build(this._schema);
                if (!JsonTokenUtils.IsStartToken(this._reader.TokenType))
                {
                    this.Push(new JsonValidatingReader.SchemaScope(JTokenType.None, this.CurrentMemberSchemas));
                }
            }
            switch (this._reader.TokenType)
            {
            case JsonToken.None:
                return;

            case JsonToken.StartObject:
            {
                this.ProcessValue();
                IList <JsonSchemaModel> schemas = this.CurrentMemberSchemas.Where(new Func <JsonSchemaModel, bool>(this.ValidateObject)).ToList <JsonSchemaModel>();
                this.Push(new JsonValidatingReader.SchemaScope(JTokenType.Object, schemas));
                this.WriteToken(this.CurrentSchemas);
                return;
            }

            case JsonToken.StartArray:
            {
                this.ProcessValue();
                IList <JsonSchemaModel> schemas2 = this.CurrentMemberSchemas.Where(new Func <JsonSchemaModel, bool>(this.ValidateArray)).ToList <JsonSchemaModel>();
                this.Push(new JsonValidatingReader.SchemaScope(JTokenType.Array, schemas2));
                this.WriteToken(this.CurrentSchemas);
                return;
            }

            case JsonToken.StartConstructor:
                this.ProcessValue();
                this.Push(new JsonValidatingReader.SchemaScope(JTokenType.Constructor, null));
                this.WriteToken(this.CurrentSchemas);
                return;

            case JsonToken.PropertyName:
                this.WriteToken(this.CurrentSchemas);
                using (IEnumerator <JsonSchemaModel> enumerator = this.CurrentSchemas.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        JsonSchemaModel schema = enumerator.Current;
                        this.ValidatePropertyName(schema);
                    }
                    return;
                }
                break;

            case JsonToken.Raw:
                this.ProcessValue();
                return;

            case JsonToken.Integer:
                this.ProcessValue();
                this.WriteToken(this.CurrentMemberSchemas);
                using (IEnumerator <JsonSchemaModel> enumerator = this.CurrentMemberSchemas.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        JsonSchemaModel schema2 = enumerator.Current;
                        this.ValidateInteger(schema2);
                    }
                    return;
                }
                goto IL_1DE;

            case JsonToken.Float:
                goto IL_1DE;

            case JsonToken.String:
                goto IL_22B;

            case JsonToken.Boolean:
                goto IL_278;

            case JsonToken.Null:
                goto IL_2C2;

            case JsonToken.Undefined:
            case JsonToken.Date:
            case JsonToken.Bytes:
                this.WriteToken(this.CurrentMemberSchemas);
                return;

            case JsonToken.EndObject:
                this.WriteToken(this.CurrentSchemas);
                foreach (JsonSchemaModel schema3 in this.CurrentSchemas)
                {
                    this.ValidateEndObject(schema3);
                }
                this.Pop();
                return;

            case JsonToken.EndArray:
                this.WriteToken(this.CurrentSchemas);
                foreach (JsonSchemaModel schema4 in this.CurrentSchemas)
                {
                    this.ValidateEndArray(schema4);
                }
                this.Pop();
                return;

            case JsonToken.EndConstructor:
                this.WriteToken(this.CurrentSchemas);
                this.Pop();
                return;
            }
            throw new ArgumentOutOfRangeException();
IL_1DE:
            this.ProcessValue();
            this.WriteToken(this.CurrentMemberSchemas);
            using (IEnumerator <JsonSchemaModel> enumerator = this.CurrentMemberSchemas.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    JsonSchemaModel schema5 = enumerator.Current;
                    this.ValidateFloat(schema5);
                }
                return;
            }
IL_22B:
            this.ProcessValue();
            this.WriteToken(this.CurrentMemberSchemas);
            using (IEnumerator <JsonSchemaModel> enumerator = this.CurrentMemberSchemas.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    JsonSchemaModel schema6 = enumerator.Current;
                    this.ValidateString(schema6);
                }
                return;
            }
IL_278:
            this.ProcessValue();
            this.WriteToken(this.CurrentMemberSchemas);
            using (IEnumerator <JsonSchemaModel> enumerator = this.CurrentMemberSchemas.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    JsonSchemaModel schema7 = enumerator.Current;
                    this.ValidateBoolean(schema7);
                }
                return;
            }
IL_2C2:
            this.ProcessValue();
            this.WriteToken(this.CurrentMemberSchemas);
            foreach (JsonSchemaModel schema8 in this.CurrentMemberSchemas)
            {
                this.ValidateNull(schema8);
            }
        }