Ejemplo n.º 1
0
        /// <summary>
        /// Loads a set of object definitions from the specified XML file.
        /// </summary>
        /// <param name="file">The file from which to load the data objects.</param>
        /// <returns>The collection of objects that were loaded.</returns>
        protected virtual IEnumerable <T> LoadDefinitionsFromXml(String file)
        {
            Contract.RequireNotEmpty(file, nameof(file));

            using (var stream = OpenFileStream(file))
            {
                var xml = XDocument.Load(stream);
                return(ObjectLoader.LoadDefinitions <T>(xml, DataElementName, DefaultObjectClass));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads a set of object definitions from the specified JSON file.
        /// </summary>
        /// <param name="file">The file from which to load the data objects.</param>
        /// <returns>The collection of objects that were loaded.</returns>
        protected virtual IEnumerable <T> LoadDefinitionsFromJson(String file)
        {
            Contract.RequireNotEmpty(file, nameof(file));

            using (var stream = OpenFileStream(file))
                using (var sreader = new StreamReader(stream))
                    using (var jreader = new JsonTextReader(sreader))
                    {
                        var json = JObject.Load(jreader);
                        return(ObjectLoader.LoadDefinitions <T>(json));
                    }
        }