bool ILanguangeExporter.AppendFhirTypeClose(ref StringBuilder sb, FhirType fhirType) { if ((fhirType.Properties == null) || (fhirType.Properties.Count == 0)) { return(true); } sb.Append("}\n"); return(true); }
bool ILanguangeExporter.AppendFhirTypeClose(ref StringBuilder sb, FhirType fhirType) { sb.Append("\t}\n"); return(true); }
bool ILanguangeExporter.AppendFhirTypeOpen(ref StringBuilder sb, FhirType fhirType) { string comment = FhirTypeManager.SanitizeComment(fhirType.Comment, _lineComment, _indentChar, 1); if ((fhirType.Properties == null) || (fhirType.Properties.Count == 0)) { //string typeName = string.IsNullOrEmpty(fhirType.TypeName) ? "object" : fhirType.TypeName; sb.Append( $"/**\n" + $" * {comment}\n" + $" * From: {fhirType.SourceFilename}\n" + $" */\n" + $"export type {fhirType.Name} = {fhirType.TypeName};\n" ); return(true); } // **** start with the interface open **** if (string.IsNullOrEmpty(fhirType.TypeName) || fhirType.Name.Equals("Element")) { sb.Append( $"/**\n" + $" * {comment}\n" + $" * From: {fhirType.SourceFilename}\n" + $" */\n" + $"export interface {fhirType.Name} {{\n" ); } else if (fhirType.Name.Equals(fhirType.TypeName, StringComparison.Ordinal)) { sb.Append( $"/**\n" + $" * {comment}\n" + $" * From: {fhirType.SourceFilename}\n" + $" */\n" + $"export interface {fhirType.Name} extends Element {{\n" ); } else { sb.Append( $"/**\n" + $" * {comment}\n" + $" * From: {fhirType.SourceFilename}\n" + $" */\n" + $"export interface {fhirType.Name} extends {fhirType.TypeName} {{\n" ); } // **** output resource type first (if necessary) **** if (FhirTypeManager.DoesTypeRequireResourceTag(fhirType.Name)) { sb.Append( $"\t/** Resource Type Name (for serialization) */\n" + $"\tresourceType: '{fhirType.Name}';\n" ); } return(true); }
bool ILanguangeExporter.AppendFhirTypeOpen(ref StringBuilder sb, FhirType fhirType) { string comment = FhirTypeManager.SanitizeComment(fhirType.Comment, _lineComment, _indentChar, 1); // **** start with the interface open **** if (string.IsNullOrEmpty(fhirType.TypeName) || fhirType.Name.Equals("Element")) { sb.Append( $"\t///<summary>\n" + $"\t///{comment}\n" + $"\t///</summary>\n" + $"\t///<source-file>{fhirType.SourceFilename}</source-file>\n" + $"\tpublic class {fhirType.NameCapitalized}\n" + $"\t{{\n" ); } else if (fhirType.Name.Equals(fhirType.TypeName, StringComparison.Ordinal)) { sb.Append( $"\t///<summary>\n" + $"\t///{comment}\n" + $"\t///</summary>\n" + $"\t///<source-file>{fhirType.SourceFilename}</source-file>\n" + $"\tpublic class {fhirType.NameCapitalized} : Element\n" + $"\t{{\n" ); } else { sb.Append( $"\t///<summary>\n" + $"\t///{comment}\n" + $"\t///</summary>\n" + $"\t///<source-file>{fhirType.SourceFilename}</source-file>\n" + $"\tpublic class {fhirType.NameCapitalized} : {fhirType.TypeName}\n" + $"\t{{\n"); } // **** output resource type first (if necessary) **** if (FhirTypeManager.DoesTypeRequireResourceTag(fhirType.Name)) { // **** add this resource to our list (for polymorphic deserialization) **** _exportedResourceNamesAndTypes.Add(fhirType.Name, fhirType.NameCapitalized); // **** output the correct ResourceType field based on style **** switch (LanguageStyle) { case (int)CSharpStyle.SystemTextJson: sb.Append( $"\t\t///<summary>Resource Type Name (for serialization)</summary>\n" + $"\t\t[JsonPropertyName(\"resourceType\")]\n" + $"\t\tpublic string ResourceType => \"{fhirType.Name}\";\n" ); break; case (int)CSharpStyle.Newtonsoft: sb.Append( $"\t\t///<summary>Resource Type Name (for serialization)</summary>\n" + $"\t\t[JsonProperty(PropertyName = \"resourceType\")]\n" + $"\t\tpublic string ResourceType => \"{fhirType.Name}\";\n" ); break; case (int)CSharpStyle.Plain: default: sb.Append( $"\t\t///<summary>Resource Type Name (for serialization)</summary>\n" + $"\t\tpublic string ResourceType => \"{fhirType.Name}\";\n" ); break; } } return(true); }