Exemple #1
0
        /// <summary>
        /// Build a POCO from an ITypedElement.
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public Base BuildFrom(ITypedElement source)
        {
            if (source == null)
            {
                throw Error.ArgumentNull(nameof(source));
            }

            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(new ComplexTypeReader(_inspector, source, settings).Deserialize(null));
            }
        }
Exemple #2
0
        public static List <ExceptionNotification> VisitAndCatch(this ITypedElement node)
        {
            var errors = new List <ExceptionNotification>();

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

            return(errors);
        }
        public XDocument buildInternal(ITypedElement source)
        {
            var dest = new XDocument();

            if (source is IExceptionSource)
            {
                using (source.Catch((o, a) => ExceptionHandler.NotifyOrThrow(o, a)))
                {
                    build(source, dest);
                }
            }
            else
            {
                build(source, dest);
            }

            return(dest);
        }
Exemple #4
0
        private JObject buildInternal(ITypedElement source)
        {
            var dest = new JObject();

            if (source is IExceptionSource)
            {
                using (source.Catch((o, a) => ExceptionHandler.NotifyOrThrow(o, a)))
                {
                    addChildren(source, dest);
                }
            }
            else
            {
                addChildren(source, dest);
            }

            return(dest);
        }
        /// <summary>
        /// Build a POCO from an ITypedElement.
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public Base BuildFrom(ITypedElement source)
        {
            if (source == null)
            {
                throw Error.ArgumentNull(nameof(source));
            }

            if (source is IExceptionSource)
            {
                using (source.Catch((o, a) => ExceptionHandler.NotifyOrThrow(o, a)))
                {
                    return(build());
                }
            }
            else
            {
                return(build());
            }

            Base build()
            {
                var typeToBuild = ModelInfo.GetTypeForFhirType(source.InstanceType);

                if (typeToBuild == null)
                {
                    ExceptionHandler.NotifyOrThrow(this,
                                                   ExceptionNotification.Error(
                                                       new StructuralTypeException($"While building a POCO: There is no .NET type representing the FHIR type '{source.InstanceType}'.")));

                    return(null);
                }

                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());
            }
        }