コード例 #1
0
ファイル: FileMappingConverter.cs プロジェクト: zyj0021/docfx
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var model = new FileMapping();
            var value = reader.Value;
            IEnumerable <JToken> jItems;

            if (reader.TokenType == JsonToken.StartArray)
            {
                jItems = JArray.Load(reader);
            }
            else if (reader.TokenType == JsonToken.String)
            {
                jItems = JRaw.Load(reader);
            }
            else
            {
                jItems = JObject.Load(reader);
            }

            if (jItems is JValue)
            {
                model.Add(FileModelParser.ParseItem(jItems.ToString()));
            }
            else if (jItems is JObject)
            {
                model.Add(FileModelParser.ParseItem((JToken)jItems));
            }
            else
            {
                foreach (var item in jItems)
                {
                    FileMappingItem itemModel = FileModelParser.ParseItem(item);
                    model.Add(itemModel);
                }
            }

            return(model);
        }
コード例 #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var model = new MergeJsonConfig();
            var value = reader.Value;
            IEnumerable <JToken> jItems;

            if (reader.TokenType == JsonToken.StartArray)
            {
                jItems = JArray.Load(reader);
            }
            else if (reader.TokenType == JsonToken.String)
            {
                jItems = JRaw.Load(reader);
            }
            else
            {
                jItems = JObject.Load(reader);
            }

            if (jItems is JValue one)
            {
                model.Add(serializer.Deserialize <MergeJsonItemConfig>(one.CreateReader()));
            }
            else if (jItems is JObject)
            {
                model.Add(serializer.Deserialize <MergeJsonItemConfig>(((JToken)jItems).CreateReader()));
            }
            else
            {
                foreach (var item in jItems)
                {
                    MergeJsonItemConfig itemModel = serializer.Deserialize <MergeJsonItemConfig>(item.CreateReader());
                    model.Add(itemModel);
                }
            }

            return(model);
        }
コード例 #3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var model = new ListWithStringFallback();
            var value = reader.Value;
            IEnumerable <JToken> jItems;

            if (reader.TokenType == JsonToken.StartArray)
            {
                jItems = JArray.Load(reader);
            }
            else if (reader.TokenType == JsonToken.StartObject)
            {
                jItems = JContainer.Load(reader);
            }
            else if (reader.TokenType == JsonToken.String)
            {
                jItems = JRaw.Load(reader);
            }
            else
            {
                jItems = JObject.Load(reader);
            }

            if (jItems is JValue)
            {
                model.Add(jItems.ToString());
            }
            else
            {
                foreach (var item in jItems)
                {
                    model.Add(item.ToString());
                }
            }

            return(model);
        }