private static List GetAllSchemasInDirectory()

in Forge.TreeWalker/src/ForgeSchemaValidator.cs [187:224]


        private static List<JObject> GetAllSchemasInDirectory(string path, bool validateAsDictionary)
        {
            List<JObject> schemaList = new List<JObject>();
            string[] files = Directory.GetFiles(path);

            if (validateAsDictionary)
            {
                Dictionary<string, ForgeTree> combinedDictionary = new Dictionary<string, ForgeTree>();

                foreach (string file in files)
                {
                    string schema = File.ReadAllText(file);
                    Dictionary<string, ForgeTree> schemaDictionary = JsonConvert.DeserializeObject<Dictionary<string, ForgeTree>>(schema);

                    foreach (KeyValuePair<string, ForgeTree> kvp in schemaDictionary)
                    {
                        if (kvp.Value.Tree == null)
                        {
                            throw new NullReferenceException("Can not deserialize the schema as dictionary in file: " + file);
                        }

                        combinedDictionary.Add(kvp.Key, kvp.Value);
                    }
                }

                return new List<JObject> { SerializeToJObject(combinedDictionary) };
            }
            else
            {
                foreach (string file in files)
                {
                    List<JObject> schemasInFile = GetSchemaFromPath(file, validateAsDictionary);
                    schemasInFile.ForEach(n => schemaList.Add(n));
                }
            }

            return schemaList;
        }