Пример #1
0
        public void WriteTo(CSharpContext context, CSharpPackage package, CSharpWriter writer)
        {
            using (var bodyWriter = new CSharpWriter())
            {
                // render body first, so usings are resolved
                using (bodyWriter.WriteIndentedBlock(prefix: $"namespace {CSharpHelpers.CombineNamespaces(package.Namespace, this.RelativeNamespace)} "))
                {
                    foreach (var fragment in Fragments)
                    {
                        fragment.WriteTo(context, package, this, bodyWriter);
                    }
                }

                bodyWriter.Flush();

                // render usings
                if (Usings.Count > 0)
                {
                    foreach (var @using in Usings)
                    {
                        writer.WriteIndented($"using {@using};");
                    }

                    writer.WriteLine();
                }

                // render body
                bodyWriter.WriteTo(writer);
            }
        }