Beispiel #1
0
        private Base buildInternal(ISourceNode source, Type typeToBuild)
        {
            if (source is IExceptionSource)
            {
                using (source.Catch((o, a) => ExceptionHandler.NotifyOrThrow(o, a)))
                {
                    return(build());
                }
            }
            else
            {
                return(build());
            }

            Base build()
            {
                var settings = new ParserSettings
                {
                    AcceptUnknownMembers   = _settings.IgnoreUnknownMembers,
                    AllowUnrecognizedEnums = _settings.AllowUnrecognizedEnums
                };

                return(typeToBuild.CanBeTreatedAsType(typeof(Resource))
                    ? new ResourceReader(source, settings).Deserialize()
                    : new ComplexTypeReader(source, settings).Deserialize(typeToBuild));
            }
        }
        /// <summary>
        /// Visits all nodes in a tree while catching any reported parsing errors. />
        /// </summary>
        /// <param name="root">The root of the tree to visit.</param>
        /// <returns>The list of all exceptions reported while visiting the tree passed in
        /// the <paramref name="root"/> argument.</returns>
        /// <seealso cref="VisitAll(ISourceNode)"/>
        public static IList <ExceptionNotification> VisitAndCatch(this ISourceNode root)
        {
            if (root == null)
            {
                throw Error.ArgumentNull(nameof(root));
            }

            var errors = new List <ExceptionNotification>();

            using (root.Catch((o, arg) => errors.Add(arg)))
            {
                root.VisitAll();
            }

            return(errors);
        }