Beispiel #1
0
        public IEnumerable <T> Parse(Stream stream)
        {
            using (var streamReader = new StreamReader(stream))
            {
                var reader = engine.InstantiateReader(streamReader);
                var root   = engine.GetRoot(reader);

                var rootObjects = new List <T>();
                var parser      = container.Retrieve <T>();
                if (engine.IsRootName(root, GetRootNames()))
                {
                    var rootObject = parser.Parse(root);
                    rootObjects.Add((T)rootObject);
                }
                else if (engine.IsRootName(root, new[] { "idunn" }))
                {
                    foreach (var child in engine.GetChildren(root, GetRootNames()))
                    {
                        var principal = parser.Parse(child);
                        rootObjects.Add((T)principal);
                    }
                }

                if (reader is IDisposable)
                {
                    ((IDisposable)reader).Dispose();
                }

                return(rootObjects);
            }
        }
Beispiel #2
0
        protected List <S> ParseChildren <S>(object node, string[] names)
        {
            var children = new List <S>();

            foreach (var child in engine.GetChildren(node, names))
            {
                var parser = container.Retrieve <S>();
                children.Add((S)parser.Parse(child));
            }
            return(children);
        }