ServiceStack.NativeTypes.CSharp.CSharpGenerator.AddConstuctor C# (CSharp) Method

AddConstuctor() private method

private AddConstuctor ( System.Text.StringBuilderWrapper sb, MetadataType type, CreateTypeOptions options ) : void
sb System.Text.StringBuilderWrapper
type MetadataType
options CreateTypeOptions
return void
        private void AddConstuctor(StringBuilderWrapper sb, MetadataType type, CreateTypeOptions options)
        {
            if (type.IsInterface())
                return;

            var initCollections = feature.ShouldInitializeCollections(type, Config.InitializeCollections);
            if (Config.AddImplicitVersion == null && !initCollections)
                return;

            var collectionProps = new List<MetadataPropertyType>();
            if (type.Properties != null && initCollections)
                collectionProps = type.Properties.Where(x => x.IsCollection()).ToList();

            var addVersionInfo = Config.AddImplicitVersion != null && options.IsRequest;
            if (!addVersionInfo && collectionProps.Count <= 0) return;

            if (addVersionInfo)
            {
                var virt = Config.MakeVirtual ? "virtual " : "";
                sb.AppendLine($"public {virt}int Version {{ get; set; }}");
                sb.AppendLine();
            }

            sb.AppendLine($"public {NameOnly(type.Name)}()");
            sb.AppendLine("{");
            sb = sb.Indent();

            if (addVersionInfo)
                sb.AppendLine($"Version = {Config.AddImplicitVersion};");

            foreach (var prop in collectionProps)
            {
                sb.AppendLine($"{prop.Name.SafeToken()} = new {Type(prop.GetTypeName(Config, allTypes), prop.GenericArgs,includeNested:true)}{{}};");
            }

            sb = sb.UnIndent();
            sb.AppendLine("}");
            sb.AppendLine();
        }