protected override void GenerateClassLine(FileGeneration fg)
        {
            // Generate class header and interfaces
            using (new LineWrapper(fg))
            {
                fg.Append("public " + (this.Abstract ? "abstract " : string.Empty) + "partial class " + Name + this.GenericTypes + " : ");

                List <string> list = new List <string>();
                if (HasBaseObject)
                {
                    var baseStr = this.BaseClass.Name;
                    if (this.BaseClass.Generics.Count > 0)
                    {
                        baseStr += "<";
                        baseStr += string.Join(", ", this.BaseClass.Generics.Select((gen) => this.BaseGenerics[gen.Key]));
                        baseStr += ">";
                    }
                    list.Add(baseStr);
                }
                list.Add(this.InterfaceStr);
                list.AddRange(
                    this.Interfaces
                    .Union(this.gen.GenerationModules
                           .SelectMany((tr) => tr.Interfaces(this)))
                    .Union(this.gen.GenerationModules
                           .SelectMany((tr) => tr.GetReaderInterfaces(this)))
                    .Union(this.GenerationInterfaces
                           .SelectMany((tr) => tr.Interfaces(this))));
                list.Add($"IEquatable<{this.ObjectName}>");
                fg.Append(string.Join(", ", list));
            }
        }
Esempio n. 2
0
        public override void GenerateCopy(FileGeneration fg)
        {
            fg.AppendLine($"public static {this.ObjectName} Copy({this.Getter_InterfaceStr} item)");
            using (new BraceWrapper(fg))
            {
                fg.AppendLine($"return new {this.ObjectName}(");
                List <string> lines = new List <string>();
                foreach (var field in this.Fields)
                {
                    lines.Add($"{field.Name}: {field.GenerateACopy("item." + field.Name)}");
                }

                for (int i = 0; i < lines.Count; i++)
                {
                    using (new DepthWrapper(fg))
                    {
                        using (new LineWrapper(fg))
                        {
                            fg.Append(lines[i]);
                            if (i != lines.Count - 1)
                            {
                                fg.Append(",");
                            }
                            else
                            {
                                fg.Append(");");
                            }
                        }
                    }
                }
            }
            fg.AppendLine();
        }
Esempio n. 3
0
        protected override void GenerateCtor(FileGeneration fg)
        {
            if (this.GeneratePublicBasicCtor)
            {
                fg.AppendLine($"public {this.Name}(");
                List <string> lines = new List <string>();
                foreach (var field in this.Fields)
                {
                    lines.Add($"{field.TypeName} {field.Name} = default({field.TypeName})");
                }
                for (int i = 0; i < lines.Count; i++)
                {
                    using (new DepthWrapper(fg))
                    {
                        using (new LineWrapper(fg))
                        {
                            fg.Append(lines[i]);
                            if (i != lines.Count - 1)
                            {
                                fg.Append(",");
                            }
                            else
                            {
                                fg.Append(")");
                            }
                        }
                    }
                }

                using (new BraceWrapper(fg))
                {
                    foreach (var field in this.Fields)
                    {
                        fg.AppendLine($"this.{field.Name} = {field.Name};");
                    }
                    fg.AppendLine("CustomCtor();");
                }
                fg.AppendLine();
            }

            fg.AppendLine($"{(this.GeneratePublicBasicCtor ? "public" : "private")} {this.Name}({this.Getter_InterfaceStr} rhs)");
            using (new BraceWrapper(fg))
            {
                foreach (var field in this.Fields)
                {
                    fg.AppendLine($"this.{field.Name} = {field.GenerateACopy("rhs." + field.Name)};");
                }
            }
            fg.AppendLine();

            fg.AppendLine("partial void CustomCtor();");
            fg.AppendLine();
        }
Esempio n. 4
0
 public LineWrapper(FileGeneration fg)
 {
     this.fg = fg;
     for (int i = 0; i < fg.Depth; i++)
     {
         fg.Append("    ");
     }
 }
Esempio n. 5
0
 private void GenerateCopyFrom(FileGeneration fg, string accessorPrefix, string rhsAccessorPrefix, string defaultAccessorPrefix, string cmdAccessor)
 {
     if (this.RefType == NoggRefType.Generic ||
         RefGen.Obj is ClassGeneration)
     {
         fg.AppendLine($"if (rhs.{this.Name} == null)");
         using (new BraceWrapper(fg))
         {
             fg.AppendLine($"{accessorPrefix}.{this.Name} = null;");
         }
         fg.AppendLine("else");
         using (new BraceWrapper(fg))
         {
             fg.AppendLine($"if ({accessorPrefix}.{this.Name} == null)");
             using (new BraceWrapper(fg))
             {
                 fg.AppendLine($"{accessorPrefix}.{this.Name} = ({this.TypeName}){rhsAccessorPrefix}.{this.Name}.Copy();");
             }
             fg.AppendLine("else");
             using (new BraceWrapper(fg))
             {
                 using (new LineWrapper(fg))
                 {
                     fg.Append(accessorPrefix + "." + this.Name + ".CopyFieldsFrom(" + rhsAccessorPrefix + "." + this.Name);
                     if (defaultAccessorPrefix != null)
                     {
                         fg.Append(", def: " + defaultAccessorPrefix + "?." + this.Name);
                     }
                     else
                     {
                         fg.Append(", null");
                     }
                     fg.Append(", cmds: " + cmdAccessor);
                     fg.Append(");");
                 }
             }
         }
     }
     else if (RefGen.Obj is StructGeneration)
     {
         fg.AppendLine($"{accessorPrefix}.{this.Name} = new {this.RefGen.Obj.Name}({rhsAccessorPrefix}.{this.Name});");
     }
 }
Esempio n. 6
0
 protected override void GenerateNotifyingCtor(FileGeneration fg)
 {
     fg.AppendLine("protected readonly INotifyingItem<" + TypeName + "> _" + this.Name + " = new NotifyingItem<" + TypeName + ">(");
     using (new DepthWrapper(fg))
     {
         if (!string.IsNullOrWhiteSpace(this.DefaultValue))
         {
             using (new LineWrapper(fg))
             {
                 if (!string.IsNullOrWhiteSpace(NameSpace))
                 {
                     fg.Append(NameSpace + ".");
                 }
                 fg.Append(EnumName + "." + this.DefaultValue);
             }
         }
     }
     fg.AppendLine(");");
 }
Esempio n. 7
0
        protected override void GenerateClassLine(FileGeneration fg)
        {
            // Generate class header and interfaces
            using (new LineWrapper(fg))
            {
                fg.Append("public partial struct " + Name + this.GenericTypes + " : ");

                List <string> list = new List <string>();
                list.Add(this.Getter_InterfaceStr);
                list.AddRange(
                    this.Interfaces
                    .Union(this.gen.GenerationModules
                           .SelectMany((tr) => tr.Interfaces(this)))
                    .Union(this.gen.GenerationModules
                           .SelectMany((tr) => tr.GetWriterInterfaces(this)))
                    .Union(this.GenerationInterfaces
                           .SelectMany((tr) => tr.Interfaces(this))));
                list.Add($"IEquatable<{this.ObjectName}>");
                fg.Append(string.Join(", ", list));
            }
        }
Esempio n. 8
0
 public void Dispose()
 {
     fg.Append("\n");
 }