/// <inheritdoc/> public bool Handle(CodeNamespaceImport obj, Context ctx) { ctx.Writer.Write("using "); if (obj is CodeNamespaceImportExt objExt && objExt.IsStatic) { ctx.Writer.Write("static "); } ctx.Writer.Write(CSharpUtils.GetValidNamespaceIdentifier(obj.Namespace)); ctx.ImportedNamespaces.Add(obj.Namespace); return(true); }
/// <summary> /// Returns the provided string as a valid c# identifier. /// </summary> /// <param name="self"></param> /// <returns></returns> public static string AsCsId(this string self) { if (self.Length == 0) { return(null); } if (self.Contains(".")) { return(CSharpUtils.GetValidNamespaceIdentifier(self)); } if (self.IsCsKeyword()) { return("@" + self); } return(self); }
/// <inheritdoc/> protected override void DoHandle(CodeNamespace obj, Context ctx) { ctx.CurrentNamespace = obj.Name; ctx.Writer.WriteLine($"namespace {CSharpUtils.GetValidNamespaceIdentifier(ctx.CurrentNamespace)}"); ctx.Writer.WriteLine("{"); ctx.Indent(); ctx.ImportedNamespaces.Clear(); GeneralUtils.HandleCollection(obj.Imports.Cast <CodeNamespaceImport>(), ctx.HandlerProvider.NamespaceImportHandler, ctx, preAction: (c) => c.Writer.Indent(c), postAction: (c) => c.Writer.WriteLine(";"), doPostActionOnLast: true); if (obj.Imports.Count > 0 && obj.Types.Count > 0) { ctx.Writer.NewLine(); } GeneralUtils.HandleCollection(obj.Types.Cast <CodeTypeDeclaration>(), ctx.HandlerProvider.TypeDeclarationHandler, ctx, preAction: (c) => c.Writer.Indent(c), postAction: (c) => c.Writer.NewLine(), doPostActionOnLast: false); ctx.Unindent(); ctx.Writer.WriteLine("}"); }
/// <inheritdoc/> protected override string AsValidNamespace(string s) { return(CSharpUtils.GetValidNamespaceIdentifier(s)); }