{"id":23329040,"url":"https://github.com/jukkahyv/sample-nested-builder-csharp","last_synced_at":"2025-10-16T15:32:18.150Z","repository":{"id":45977358,"uuid":"229436525","full_name":"jukkahyv/sample-nested-builder-csharp","owner":"jukkahyv","description":"Sample for nested builder pattern in C#","archived":false,"fork":false,"pushed_at":"2020-01-03T14:39:45.000Z","size":9,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-13T12:42:27.635Z","etag":null,"topics":["builder-pattern","csharp"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jukkahyv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-21T14:08:31.000Z","updated_at":"2023-09-18T20:44:33.000Z","dependencies_parsed_at":"2022-07-18T04:00:43.138Z","dependency_job_id":null,"html_url":"https://github.com/jukkahyv/sample-nested-builder-csharp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jukkahyv%2Fsample-nested-builder-csharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jukkahyv%2Fsample-nested-builder-csharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jukkahyv%2Fsample-nested-builder-csharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jukkahyv%2Fsample-nested-builder-csharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jukkahyv","download_url":"https://codeload.github.com/jukkahyv/sample-nested-builder-csharp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247623009,"owners_count":20968574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["builder-pattern","csharp"],"created_at":"2024-12-20T21:30:37.110Z","updated_at":"2025-10-16T15:32:18.093Z","avatar_url":"https://github.com/jukkahyv.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sample for nested builder pattern in C#\n\nMaking use of Action\u003cT\u003e callbacks and \"out\" parameters, with optional discards.\n\n```csharp\nvar docTree = new DocumentTreeBuilder()\n    .AddFolder(\"My files\", folder =\u003e folder\n        .SetIcon(\"myicon.png\")\n        .AddDocument(Model.DocumentType.Text)\n        .AddDocument(Model.DocumentType.Text)\n        .AddDocument(Model.DocumentType.Text, out var textDocument)\n        .AddSubFolder(\"Images\", imgFolder =\u003e imgFolder\n            .AddDocument(Model.DocumentType.Image, doc =\u003e doc.AddLink(textDocument))\n        )\n    , out var myFiles)\n    .AddFolder(\"Shared files\")\n    .Build();\n\nConsole.WriteLine($\"MyFiles ID: {myFiles.Id}\");\n```\n\n## Some explanation\n\nOne of the rules I follow is that the builder methods (such as ```AddDocument```) should always return the builder itself, and\nthe child builder, if necessary, should be accessed in a callback. This makes it clear when we are configuring a child object, and when parent object, and avoids the need to use special GetParent or Build calls.\nThe children can be chained easily.\n\nAdditionally, all created objects can be exported as \"out\" parameters, if they need to be accessed later.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjukkahyv%2Fsample-nested-builder-csharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjukkahyv%2Fsample-nested-builder-csharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjukkahyv%2Fsample-nested-builder-csharp/lists"}