private static void AddNamespace( this CodeBuilder builder, string @namespace, Action <CodeBuilder> addContent) { builder.WriteLine($"Namespace {@namespace}"); builder.BeginIndent(); addContent?.Invoke(builder); builder.EndIndent(); builder.WriteLine("End Namespace"); }
private static void AddEnum( this CodeBuilder builder, EnumDefinition enumDefinition, StorageType storageType) { var assemblyName = typeof(VisualBasicExporter).Assembly.GetName(); if (!string.IsNullOrEmpty(enumDefinition.Comment)) { builder.AddSummary(enumDefinition.Comment); } builder.WriteLine($"<GeneratedCode(\"{assemblyName.Name}\", \"{assemblyName.Version}\")>"); if (storageType == StorageType.Implicit) { builder.WriteLine($"Public Enum {enumDefinition.Identifier}"); } else { builder.WriteLine($"Public Enum {enumDefinition.Identifier} As {storageType.GetVisualBasicKeyword()}"); } builder.BeginIndent(); var newlineBetweenEntries = enumDefinition.HasAnyEntryComments; var first = true; foreach (var entry in enumDefinition.Entries) { if (!first && newlineBetweenEntries) { builder.WriteEndLine(); } first = false; if (!string.IsNullOrEmpty(entry.Comment)) { builder.AddSummary(entry.Comment); } builder.WriteLine($"{entry.Name} = {entry.Value}"); } builder.EndIndent(); builder.WriteLine("End Enum"); }
private static void StartScope(this CodeBuilder builder, CurlyBracketMode curlyBracketMode) { switch (curlyBracketMode) { case CurlyBracketMode.NewLine: if (builder.IsLineActive) { builder.WriteEndLine(); } builder.WriteLine("{"); break; case CurlyBracketMode.SameLine: if (!builder.IsNewLine && !builder.IsSpace) { builder.WriteSpace(); } builder.Append("{"); builder.WriteEndLine(); break; } builder.BeginIndent(); }