Newtonsoft.Json.Schema.JsonSchemaResolver.GetSchema C# (CSharp) Méthode

GetSchema() public méthode

Gets a JsonSchema for the specified id.
public GetSchema ( string id ) : JsonSchema
id string The id.
Résultat JsonSchema
    public virtual JsonSchema GetSchema(string id)
    {
      JsonSchema schema = LoadedSchemas.SingleOrDefault(s => s.Id == id);
      return schema;
    }
  }

Usage Example

        private JsonSchema BuildSchema()
        {
            if (_reader.TokenType != JsonToken.StartObject)
            {
                throw new Exception("Expected StartObject while parsing schema object, got {0}.".FormatWith(CultureInfo.InvariantCulture, _reader.TokenType));
            }

            _reader.Read();
            // empty schema object
            if (_reader.TokenType == JsonToken.EndObject)
            {
                Push(new JsonSchema());
                return(Pop());
            }

            string propertyName = Convert.ToString(_reader.Value, CultureInfo.InvariantCulture);

            _reader.Read();

            // schema reference
            if (propertyName == JsonSchemaConstants.ReferencePropertyName)
            {
                string id = (string)_reader.Value;

                // skip to the end of the current object
                while (_reader.Read() && _reader.TokenType != JsonToken.EndObject)
                {
                    if (_reader.TokenType == JsonToken.StartObject)
                    {
                        throw new Exception("Found StartObject within the schema reference with the Id '{0}'"
                                            .FormatWith(CultureInfo.InvariantCulture, id));
                    }
                }

                JsonSchema referencedSchema = _resolver.GetSchema(id);
                if (referencedSchema == null)
                {
                    throw new Exception("Could not resolve schema reference for Id '{0}'.".FormatWith(CultureInfo.InvariantCulture, id));
                }

                return(referencedSchema);
            }

            // regular ol' schema object
            Push(new JsonSchema());

            ProcessSchemaProperty(propertyName);

            while (_reader.Read() && _reader.TokenType != JsonToken.EndObject)
            {
                propertyName = Convert.ToString(_reader.Value, CultureInfo.InvariantCulture);
                _reader.Read();

                ProcessSchemaProperty(propertyName);
            }

            return(Pop());
        }
All Usage Examples Of Newtonsoft.Json.Schema.JsonSchemaResolver::GetSchema