Exemple #1
0
        /// <summary>Writes a header.</summary>
        private void WriteHeader()
        {
            _writer.WriteLineIndented("// <auto-generated/>");
            _writer.WriteLineIndented($"// Contents of: {_info.PackageName} version: {_info.VersionString}");
            _writer.WriteLineIndented($"  // Primitive Naming Style: {FhirTypeBase.NamingConvention.None}");
            _writer.WriteLineIndented($"  // Complex Type / Resource Naming Style: {FhirTypeBase.NamingConvention.PascalCase}");
            _writer.WriteLineIndented($"  // Element Naming Style: {FhirTypeBase.NamingConvention.PascalCase}");
            _writer.WriteLineIndented($"  // Enum Naming Style: {FhirTypeBase.NamingConvention.PascalCase}");
            _writer.WriteLineIndented($"  // Interaction Naming Style: {FhirTypeBase.NamingConvention.None}");
            _writer.WriteLineIndented($"  // Extension Support: {_options.ExtensionSupport}");

            if ((_options.ExportList != null) && _options.ExportList.Any())
            {
                string restrictions = string.Join("|", _options.ExportList);
                _writer.WriteLineIndented($"  // Restricted to: {restrictions}");
            }

            if ((_options.LanguageOptions != null) && (_options.LanguageOptions.Count > 0))
            {
                foreach (KeyValuePair <string, string> kvp in _options.LanguageOptions)
                {
                    _writer.WriteLineIndented($"  // Language option: \"{kvp.Key}\" = \"{kvp.Value}\"");
                }
            }

            _writer.WriteLine(string.Empty);

            _writer.WriteLineIndented("using System;");
            _writer.WriteLineIndented("using System.Collections.Generic;");
            _writer.WriteLineIndented("using Newtonsoft.Json;");
            _writer.WriteLineIndented("using Newtonsoft.Json.Linq;");
            _writer.WriteLine(string.Empty);
        }
        /// <summary>Writes a complex.</summary>
        /// <param name="complex">The complex.</param>
        private void WriteComplex(
            FhirComplex complex)
        {
            bool indented = false;

            // write this type's line, if it's a root element
            // (sub-properties are written with cardinality in the prior loop)
            if (_writer.Indentation == 0)
            {
                string experimental = complex.IsExperimental ? " (experimental)" : string.Empty;

                _writer.WriteLine($"- {complex.Name}: {complex.BaseTypeName}{experimental}");
                _writer.IncreaseIndent();
                indented = true;
            }

            // write elements
            WriteElements(complex);

            // check for extensions
            if (_info.ExtensionsByPath.ContainsKey(complex.Path))
            {
                WriteExtensions(_info.ExtensionsByPath[complex.Path].Values);
            }

            // check for search parameters on this object
            if (complex.SearchParameters != null)
            {
                WriteSearchParameters(complex.SearchParameters.Values);
            }

            // check for type operations
            if (complex.TypeOperations != null)
            {
                WriteOperations(complex.TypeOperations.Values, true);
            }

            // check for instance operations
            if (complex.InstanceOperations != null)
            {
                WriteOperations(complex.TypeOperations.Values, false);
            }

            if (_info.ProfilesByBaseType.ContainsKey(complex.Path))
            {
                WriteProfiles(_info.ProfilesByBaseType[complex.Path].Values);
            }

            if (indented)
            {
                _writer.DecreaseIndent();
            }
        }
Exemple #3
0
        /// <summary>Writes an indented comment.</summary>
        /// <param name="writer">The writer to write the comment to.</param>
        /// <param name="value">The value.</param>
        /// <param name="isSummary">(Optional) True if is summary, false if not.</param>
        /// <param name="singleLine">(Optional) True if this is a short comment using a single line comment prefix. Implies isSummary = false.</param>
        public static void WriteIndentedComment(ExportStreamWriter writer, string value, bool isSummary = true, bool singleLine = false)
        {
            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            if (singleLine)
            {
                isSummary = false;
            }

            if (isSummary)
            {
                writer.WriteLineIndented("/// <summary>");
            }

            string comment = value.Replace('\r', '\n').Replace("\r\n", "\n").Replace("\n\n", "\n")
                             .Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;");

            string[] lines = comment.Split('\n');
            foreach (string line in lines)
            {
                writer.WriteIndented(singleLine ? "// " : "/// ");
                writer.WriteLine(line);
            }

            if (isSummary)
            {
                writer.WriteLineIndented("/// </summary>");
            }
        }
Exemple #4
0
        /// <summary>Closes the scope.</summary>
        /// <param name="writer">          The writer to write the comment to.</param>
        /// <param name="includeSemicolon">(Optional) True to include, false to exclude the semicolon.</param>
        /// <param name="suppressNewline"> (Optional) True to suppress, false to allow the newline.</param>
        public static void CloseScope(ExportStreamWriter writer, bool includeSemicolon = false, bool suppressNewline = false)
        {
            writer.DecreaseIndent();

            if (includeSemicolon)
            {
                writer.WriteLineIndented("};");
            }
            else
            {
                writer.WriteLineIndented("}");
            }

            if (!suppressNewline)
            {
                writer.WriteLine(string.Empty);
            }
        }