示例#1
0
        /// <inheritdoc />
        public override IMetadataSchemaProvider ReadJson(
            JsonReader reader,
            Type objectType,
            IMetadataSchemaProvider?existingValue,
            bool hasExistingValue,
            JsonSerializer serializer)
        {
            if (Options.UseSchemasRoot)
            {
                ISchemaRepository?schemaRepository = reader.AsMetadataProvider().GetMetadata <ISchemaRepository>();
                if (schemaRepository == null)
                {
                    schemaRepository = new SchemaRepository();

                    // Load json in memory (first iteration).
                    JObject jObject = JObject.Load(reader);
                    if (jObject.Property(Options.SchemasRootName)?.Value is JObject schemasRoot)
                    {
                        foreach (JProperty property in schemasRoot.Properties())
                        {
                            string schemaName    = property.Name;
                            string root          = $"#/{Options.SchemasRootName}/";
                            string referenceName = root + schemaName;

                            JProperty?jProperty = ((JObject)property.Value).Property("$metadata.schema.compact");
                            if (jProperty is { First: { } schemaBody })
示例#2
0
        /// <inheritdoc />
        public override IPropertyContainer ReadJson(
            JsonReader reader,
            Type objectType,
            IPropertyContainer?existingValue,
            bool hasExistingValue,
            JsonSerializer serializer)
        {
            IPropertySet?schema            = null;
            bool         hasSchemaFromType = false;
            bool         hasSchemaFromJson = false;

            var propertyContainer = new MutablePropertyContainer();

            IPropertySet?knownPropertySet = objectType.GetSchemaByKnownPropertySet();

            if (knownPropertySet != null)
            {
                schema            = knownPropertySet;
                hasSchemaFromType = true;
            }

            ISchemaRepository?schemaRepository = reader.AsMetadataProvider().GetMetadata <ISchemaRepository>();

            if (Options.ReadSchemaFirst)
            {
                JObject jObject = JObject.Load(reader);

                JProperty?jProperty = jObject.Property("$metadata.schema.compact");
                if (jProperty is { First : { } schemaBody })