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;
        }
示例#2
0
        internal static Dictionary <string, object> GetGlobalMetadataFromOption(Dictionary <string, object> globalMetadataFromConfig, string globalMetadataFilePath, ListWithStringFallback globalMetadataFilePaths, string globalMetadataContent)
        {
            Dictionary <string, object> globalMetadata = null;

            if (globalMetadataContent != null)
            {
                using (var sr = new StringReader(globalMetadataContent))
                {
                    try
                    {
                        globalMetadata = JsonUtility.Deserialize <Dictionary <string, object> >(sr, GetToObjectSerializer());
                    }
                    catch (JsonException e)
                    {
                        Logger.LogWarning($"Metadata from \"--globalMetadata {globalMetadataContent}\" is not a valid JSON format global metadata, ignored: {e.Message}");
                    }
                }
            }

            if (globalMetadataFilePaths != null)
            {
                foreach (var filePath in globalMetadataFilePaths)
                {
                    globalMetadata = MergeMetadataFromFile("globalMetadata", globalMetadata, filePath, path => JsonUtility.Deserialize <Dictionary <string, object> >(path), MergeGlobalMetadataItem);
                }
            }

            if (globalMetadataFilePath != null)
            {
                globalMetadata = MergeMetadataFromFile("globalMetadata", globalMetadata, globalMetadataFilePath, path => JsonUtility.Deserialize <BuildJsonConfig>(path)?.GlobalMetadata, MergeGlobalMetadataItem);
            }

            return(OptionMerger.MergeDictionary(
                       new DictionaryMergeContext <object>("globalMetadata from docfx config file", globalMetadataFromConfig),
                       new DictionaryMergeContext <object>("globalMetadata merged with command option and globalMetadata config file", globalMetadata),
                       MergeGlobalMetadataItem));
        }
示例#3
0
        internal static Dictionary <string, FileMetadataPairs> GetFileMetadataFromOption(Dictionary <string, FileMetadataPairs> fileMetadataFromConfig, string fileMetadataFilePath, ListWithStringFallback fileMetadataFilePaths)
        {
            var fileMetadata = new Dictionary <string, FileMetadataPairs>();

            if (fileMetadataFilePaths != null)
            {
                foreach (var filePath in fileMetadataFilePaths)
                {
                    fileMetadata = MergeMetadataFromFile("fileMetadata", fileMetadata, filePath, path => JsonUtility.Deserialize <Dictionary <string, FileMetadataPairs> >(path), MergeFileMetadataPairs);
                }
            }

            if (fileMetadataFilePath != null)
            {
                fileMetadata = MergeMetadataFromFile("fileMetadata", fileMetadata, fileMetadataFilePath, path => JsonUtility.Deserialize <BuildJsonConfig>(path)?.FileMetadata, MergeFileMetadataPairs);
            }

            return(OptionMerger.MergeDictionary(
                       new DictionaryMergeContext <FileMetadataPairs>("fileMetadata from docfx config file", fileMetadataFromConfig),
                       new DictionaryMergeContext <FileMetadataPairs>("fileMetadata from fileMetadata config file", fileMetadata),
                       MergeFileMetadataPairs));
        }