/// <summary>Determines serialization format by inspecting the file extension.</summary>
 /// <param name="path">File path to a FHIR artifact.</param>
 /// <returns>A constant string value as defined by <see cref="FhirSerializationFormats"/>, or <c>null</c>.</returns>
 public static string GetSerializationFormat(string path)
 {
     if (FhirFileFormats.HasXmlExtension(path))
     {
         return(FhirSerializationFormats.Xml);
     }
     if (FhirFileFormats.HasJsonExtension(path))
     {
         return(FhirSerializationFormats.Json);
     }
     return(null);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="INavigatorStream"/> instance to access the contents of a
        /// serialized resource, independent of the underlying resource serialization format.
        /// </summary>
        /// <param name="path">File path specification of a FHIR resource file.</param>
        /// <returns>A new <see cref="INavigatorStream"/> instance, or <c>null</c> (unsupported file extension).</returns>
        /// <remarks>Supports FHIR resource files with ".xml" and ".json" extensions.</remarks>
        public static INavigatorStream Create(string path)
        {
            if (FhirFileFormats.HasXmlExtension(path))
            {
                return(XmlNavigatorStream.FromPath(path));
            }
            if (FhirFileFormats.HasJsonExtension(path))
            {
                return(JsonNavigatorStream.FromPath(path));
            }

            // Unsupported extension
            return(null);
        }
        // Called by DefaultNavigatorStream.Create(string path, bool disposeStream)
        internal INavigatorStream Create(string path, bool disposeStream)
        {
            if (FhirFileFormats.HasXmlExtension(path))
            {
                return(XmlNavigatorStream.FromPath(path, disposeStream, XmlParsingSettings));
            }
            if (FhirFileFormats.HasJsonExtension(path))
            {
                return(JsonNavigatorStream.FromPath(path, disposeStream, JsonParsingSettings));
            }

            // Unsupported extension
            if (ThrowOnUnsupportedFormat)
            {
                throw Error.NotSupported($"Unsupported file format ('{path}').");
            }
            return(null);
        }