{"id":20952146,"url":"https://github.com/tparviainen/query-string-generator","last_synced_at":"2025-05-14T04:32:02.241Z","repository":{"id":37237552,"uuid":"502532525","full_name":"tparviainen/query-string-generator","owner":"tparviainen","description":"C# incremental generator to create a method that returns the query string of the object.","archived":false,"fork":false,"pushed_at":"2024-12-04T16:49:14.000Z","size":88,"stargazers_count":6,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-06T06:29:12.618Z","etag":null,"topics":["csharp-generator","csharp-sourcegenerator","incremental-generator"],"latest_commit_sha":null,"homepage":"","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/tparviainen.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-12T06:00:31.000Z","updated_at":"2024-11-25T16:56:05.000Z","dependencies_parsed_at":"2023-12-29T11:29:31.038Z","dependency_job_id":"aae8c87f-dce0-4101-bf0e-907a798a5aed","html_url":"https://github.com/tparviainen/query-string-generator","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/tparviainen%2Fquery-string-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tparviainen%2Fquery-string-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tparviainen%2Fquery-string-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tparviainen%2Fquery-string-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tparviainen","download_url":"https://codeload.github.com/tparviainen/query-string-generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254071293,"owners_count":22009766,"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":["csharp-generator","csharp-sourcegenerator","incremental-generator"],"created_at":"2024-11-19T01:00:57.693Z","updated_at":"2025-05-14T04:32:02.003Z","avatar_url":"https://github.com/tparviainen.png","language":"C#","funding_links":[],"categories":["Content"],"sub_categories":["170. [QueryStringGenerator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/QueryStringGenerator) , in the [EnhancementClass](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementclass) category"],"readme":"# Query String Generator\n\nC# incremental generator to create a method that returns the query string of the object.\n\n# Usage\n\n## 1. Install the [NuGet](https://www.nuget.org/packages/QueryStringGenerator) package\n\n```\nPM\u003e Install-Package QueryStringGenerator\n```\n\n## 2. Update the Model(s)\n\nClass must be decorated with `QueryString` attribute, which is declared in `QueryStringGenerator` namespace.\n\n```csharp\nusing QueryStringGenerator;\n\n[QueryString]\npublic class Model\n{\n    public int? Limit { get; set; }\n    public int? Offset { get; set; }\n    public string? Sort { get; set; }\n}\n```\n\n## 3. Call `ToQueryString` Method to the Instance of the Class\n\nBy default the generated method name is `ToQueryString`, which when called returns the query string of the object.\n\n```csharp\nvar model = new Model\n{\n    Limit = 10,\n    Sort = \"Price\"\n};\n\nConsole.WriteLine($\"Query string: {model.ToQueryString()}\");\n\n/*\nThis code example produces the following results:\n\nQuery string: \u0026limit=10\u0026sort=Price\n*/\n```\n\n# Generated Source Code\n\nBelow is the auto-generated extension method for the class defined in step 2. above.\n\n```csharp\n// \u003cauto-generated /\u003e\n\nnamespace QueryStringGenerator.App.Models\n{\n    [global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"QueryStringGenerator\", \"1.0.0\")]\n    public static class QueryStringExtensionForModel\n    {\n        public static string ToQueryString(this Model _this)\n        {\n            if (_this == null)\n            {\n                return string.Empty;\n            }\n\n            var sb = new global::System.Text.StringBuilder();\n\n            if (_this.Limit != null)\n            {\n                sb.Append($\"\u0026limit={_this.Limit}\");\n            }\n\n            if (_this.Offset != null)\n            {\n                sb.Append($\"\u0026offset={_this.Offset}\");\n            }\n\n            if (_this.Sort != null)\n            {\n                sb.Append($\"\u0026sort={System.Net.WebUtility.UrlEncode(_this.Sort)}\");\n            }\n\n            return sb.ToString();\n        }\n    }\n}\n```\n\n# Supported Data Types\n\n- Nullable value types, including enums\n- Reference types\n\n**NOTE:** The query string _value_ for enum is the name of the enum starting with a lowercase character.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftparviainen%2Fquery-string-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftparviainen%2Fquery-string-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftparviainen%2Fquery-string-generator/lists"}