static void GenerateWith(RecordInfo record, CodeWriter writer)
        {
            if (record.Items.Length == 0)
            {
                return;
            }

            if (!(record.IncludeWith || record.Items.Any(x => x.IncludeWith)))
            {
                return;
            }

            for (int i = 0; i < record.Items.Length; ++i)
            {
                if (!(record.IncludeWith || record.Items[i].IncludeWith))
                {
                    continue;
                }

                writer.WriteLine();
                ItemInfo classItem    = record.Items[i];
                string   itemTypeName = GetTypeName(classItem, true);
                writer.WriteLine($"public {record.Name} With{classItem.Name} ({itemTypeName} {classItem.Name.CamelPrefix ()})");
                writer.WriteLine("{");
                writer.Indent();

                writer.WriteLine($"return new {record.Name} ({CreateConstructorInvokeArgs (record, i)});");

                writer.Dedent();
                writer.WriteLine("}");
            }
        }
Exemple #2
0
 void GenerateNamespaceHeader(CodeWriter writer)
 {
     if (!string.IsNullOrEmpty(File.GlobalNamespace))
     {
         writer.WriteLine($"namespace {File.GlobalNamespace}");
         writer.WriteLine("{");
         writer.Indent();
     }
 }
Exemple #3
0
        static void GenerateConstructor(RecordInfo record, CodeWriter writer)
        {
            if (record.Items.Length == 0)
            {
                return;
            }

            writer.WriteLine($"public {record.Name} ({CreateConstructorArgs (record)})");
            writer.WriteLine("{");
            writer.Indent();
            foreach (var classItem in record.Items.Where(x => !x.IsMutable))
            {
                writer.WriteLine($"{classItem.Name} = {GenerateFieldAssign (classItem)};");
            }
            writer.Dedent();
            writer.WriteLine("}");
        }
Exemple #4
0
        static void GenerateRecord(RecordInfo record, CodeWriter writer)
        {
            GenerateClassHeader(record, writer);
            writer.Indent();

            foreach (var classItem in record.Items)
            {
                GenerateProperty(classItem, writer);
            }
            if (record.Items.Length > 0)
            {
                writer.WriteLine();
            }
            GenerateConstructor(record, writer);
            GenerateWith(record, writer);

            writer.Dedent();
            GenerateInjection(record, writer);

            GenerateClassFooter(writer);
        }