{"id":31820614,"url":"https://github.com/0xneshi/topystring","last_synced_at":"2025-10-11T12:51:28.304Z","repository":{"id":55928939,"uuid":"271992180","full_name":"0xNeshi/topystring","owner":"0xNeshi","description":".NET System.Collections ToString extension for converting collections to a string in the format that is based on the one in Python ","archived":false,"fork":false,"pushed_at":"2025-01-06T12:32:43.000Z","size":199,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-19T01:49:14.800Z","etag":null,"topics":["collections","csharp","dotnet","python-format","tostring"],"latest_commit_sha":null,"homepage":"https://0xNeshi.github.io/topystring/","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/0xNeshi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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":"2020-06-13T11:03:20.000Z","updated_at":"2025-01-06T12:36:04.000Z","dependencies_parsed_at":"2024-08-09T13:30:50.217Z","dependency_job_id":"9683f5b1-c1bd-4d39-b403-597df495f2fd","html_url":"https://github.com/0xNeshi/topystring","commit_stats":null,"previous_names":["0xneshi/topystring","misicnenad/topystring"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/0xNeshi/topystring","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xNeshi%2Ftopystring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xNeshi%2Ftopystring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xNeshi%2Ftopystring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xNeshi%2Ftopystring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xNeshi","download_url":"https://codeload.github.com/0xNeshi/topystring/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xNeshi%2Ftopystring/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007193,"owners_count":26084249,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["collections","csharp","dotnet","python-format","tostring"],"created_at":"2025-10-11T12:51:14.873Z","updated_at":"2025-10-11T12:51:28.295Z","avatar_url":"https://github.com/0xNeshi.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ToPyString\n\n[![Build \u0026 Test .NET Library](https://github.com/0xNeshi/topystring/actions/workflows/build-dotnet-core.yml/badge.svg)](https://github.com/0xNeshi/topystring/actions/workflows/build-dotnet-core.yml)\n[![NuGet](https://img.shields.io/nuget/v/Collections.Extensions.ToPyString?logo=nuget)](https://www.nuget.org/packages/Collections.Extensions.ToPyString)\n[![License](https://img.shields.io/github/license/misicnenad/topystring?color=yellow)](https://opensource.org/licenses/MIT)\n[![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen)](https://github.com/0xNeshi/topystring/issues)\n\nToPyString is a .NET System.Collections extension for converting collections to a string in Python format.\n\nThe reason this small project exists is because it's a shame that C# doesn't have an in-built way of stringifying collections (like many other languages do). Although creating a `ToString` method for your collections isn't difficult, you shouldn't be wasting time implementing rudimentary things on every project... especially on projects you're using to just quickly try something out and Console.WriteLine the output.\n\n## Summary\n\n- [Getting Started](#getting-started)\n- [Prerequisites](#prerequisites)\n- [Installing](#installing)\n- [Using ToPyString](#using-topystring)\n- [Runing the tests](#running-the-tests)\n- [Break down of unit tests](#break-down-of-unit-tests)\n- [Contact](#contact)\n- [Contributing](#contributing)\n- [Authors](#authors)\n- [License](#license)\n\n## Getting Started\n\nFollow these instructions to see how simple it is to use `ToPyString`.\n\n### Prerequisites\n\nThis package supports every .NET version from the .NET Standard 2.0 and up!\n\nYou can find the .NET download page [here](https://dotnet.microsoft.com/download).\n\n### Installing\n\nYou can get `ToPyString` by installing the [Collections.Extensions.ToPyString](https://www.nuget.org/packages/Collections.Extensions.ToPyString) NuGet package:\n\n```powershell\nInstall-Package Collections.Extensions.ToPyString\n```\n\nOr via the NET command line interface:\n\n```bash\ndotnet add package Collections.Extensions.ToPyString\n```\n\n## Using ToPyString\n\n`ToPyString` is an extension method that can be used on all .NET types.\n\n- List:\n\n```csharp\nvar list = new List\u003cobject\u003e { 11, \"john\", \"doe\" };\n\nConsole.WriteLine(list.ToPyString()); // Output: [11, 'john', 'doe']\n```\n\n -Self-containing List:\n\n```csharp\nvar list = new List\u003cobject\u003e { 11 };\nlist.Add(list);\n\nConsole.WriteLine(list.ToPyString()); // Output: [11, [...]]\n```\n\n- Dictionary:\n\n```csharp\nvar dictionary = new Dictionary\u003cobject, object\u003e { [1] = \"key1\", [\"key2\"] = 2, [new object()] = null };\n\nConsole.WriteLine(dictionary.ToPyString()); // Output: {1: 'key1', 'key2': 2, System.Object: null}\n```\n\n- Self-containing Dictionary:\n\n```csharp\nvar dictionary = new Dictionary\u003cobject, object\u003e { [1] = \"key1\" };\ndictionary.Add(\"self\", dictionary);\n\nConsole.WriteLine(dictionary.ToPyString()); // Output: {1: 'key1', 'self': {...}}\n```\n\n- String and primitive types:\n\n```csharp\nvar str = \"some string\";\nvar intNum = 11;\nvar doubleNum = 1.012d;\n\nConsole.WriteLine(str.ToPyString()); // Output: some string\nConsole.WriteLine(intNum.ToPyString()); // Output: 11\nConsole.WriteLine(doubleNum.ToPyString()); // Output: 1.012\n```\n\n---\n\n### Be careful when using ToPyString with `dynamic` type\n\nBecause of the way _dynamic_ type is implemented the CLR will throw a `RuntimeBinderException` if you try to call the `ToPyString` extension method directly on a `dynamic` object. To get around this issue simply use `ToPyString` as a regular static method.\n\n**Wrong use with `dynamic`:**\n\n```csharp\ndynamic dynObject = new { SomeField = 1 };\n\nConsole.WriteLine(dynObject.ToPyString()); // --\u003e will throw a RuntimeBinderException\n```\n\n**Correct use:**\n\n```csharp\ndynamic dynObject = new { SomeField = 1 };\n\nConsole.WriteLine(CollectionExtensions.ToPyString(dynObject)); // Output: { SomeField = 1 }\n```\n\nIf you have a collection that contains a `dynamic` object, you can use the `ToPyString` as usual:\n\n```csharp\ndynamic dynObject = new { SomeField = 1 };\nvar list = new List\u003cobject\u003e { dynObject };\n\nConsole.WriteLine(list.ToPyString()); // Output: [{ SomeField = 1 }]\n```\n\n## Running the tests\n\nTo run the tests using the command line use:\n\n```bash\ndotnet test\n```\n\nAlternatively, if you're using Visual Studio, you have a button that runs the tests for you, so you can also use that.\n\n### Break down of unit tests\n\nThe tests are mainly testing whether C# Collections types are converted to string in the expected Python format, and confirming that calling `ToPyString` on non-collections \nbehaves the same way that calling `ToString` would.\n\n```csharp\n[Fact]\npublic void Prints_List_Of_Ints()\n{\n    var list = new List\u003cint\u003e { 1, 2, -3, 100 };\n    var expectedResult = \"[1, 2, -3, 100]\";\n\n    var result = list.ToPyString();\n\n    Assert.Equal(expectedResult, result);\n}\n```\n\n## Contact\n\nHave a question or an issue about ToPyString?\nCreate an [issue](https://github.com/misicnenad/topystring/issues/new)!\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to the project.\n\n## Authors\n\n- **Nenad** - [0xNeshi](https://github.com/0xNeshi)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n\n## Final thoughts\n\nIf you found this extension helpfull then please give it a star 🌟 and share it with others, help them so they also NOT waste time on stringifying collections.\n\nFinally, if you have any suggestions on refactoring the codebase to make it simpler, more extensible, more elegant - please let me know, I LOVE refactoring! \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xneshi%2Ftopystring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xneshi%2Ftopystring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xneshi%2Ftopystring/lists"}