{"id":13629700,"url":"https://github.com/Burgyn/MMLib.ToString","last_synced_at":"2025-04-17T09:35:49.740Z","repository":{"id":41193559,"uuid":"360828414","full_name":"Burgyn/MMLib.ToString","owner":"Burgyn","description":"Source code generator for generating `ToString` method","archived":false,"fork":false,"pushed_at":"2023-01-27T11:27:21.000Z","size":44,"stargazers_count":17,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-08T09:43:09.897Z","etag":null,"topics":[],"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/Burgyn.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":"2021-04-23T09:17:07.000Z","updated_at":"2024-08-16T15:45:32.000Z","dependencies_parsed_at":"2023-02-15T08:31:03.976Z","dependency_job_id":null,"html_url":"https://github.com/Burgyn/MMLib.ToString","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/Burgyn%2FMMLib.ToString","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Burgyn%2FMMLib.ToString/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Burgyn%2FMMLib.ToString/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Burgyn%2FMMLib.ToString/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Burgyn","download_url":"https://codeload.github.com/Burgyn/MMLib.ToString/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223640784,"owners_count":17178084,"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":[],"created_at":"2024-08-01T22:01:16.868Z","updated_at":"2024-11-08T20:31:44.000Z","avatar_url":"https://github.com/Burgyn.png","language":"C#","readme":"# MMLib.ToString\n\n\u003e This is my first attempt with a [C# Source generators](https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/).\n\n[![Publish package](https://github.com/Burgyn/MMLib.ToString/actions/workflows/deploy.yml/badge.svg)](https://github.com/Burgyn/MMLib.ToString/actions/workflows/deploy.yml)\n\n### How to install\n\n`dotnet add package MMLib.ToString.Generator`\n\n### Motivation \n\nWe all love the new `record` type. One of the completely marginal features is that it has an override `ToString()` method.\n\n```csharp\npublic record Person(int Id, string Name);\n\nPerson person = new (2, \"Milan\");\n\nConsole.WriteLine(person); //Output: Person {Id = 2, Name = Milan}\n```\n\nWhy don't standard classes have such an output? Why do I have to implement this over and over again in each class? How many times have you override a standard `ToString` for debug purpouse?\n\nI decided to try the source generator to allow it to generate a similar override for all classes marked with my attribute *(I want to use the Source generators for other purposes, this came to me as a nice example to try 😉)*\n\n\n### Examples\n\n```csharp\n[ToString()]\npublic partial class Person\n{\n    public int Id { get; set; }\n\n    public string Name { get; set; }\n\n    public Foo Foo { get; set; } = new Foo()\n    {\n        Id = 1,\n        Bar = \"bar\",\n        Created = DateTime.Now,\n        Name = \"somebody\"\n    };\n}\n\n[ToString()]\npublic partial class Foo\n{\n    public int Id { get; set; }\n\n    public string Bar { get; set; }\n\n    public string Name { get; set; }\n\n    public DateTime Created { get; set; }\n}\n\nvar p = new Person() { Id = 1, Name = \"Nobody\" };\nConsole.WriteLine(p); \n//Output:\n//Person {Id = 1, Name = Nobody, Foo = Foo {Id = 1, Bar = bar, Name = somebody, Created = 24. 4. 2021 20:39:04}}\n```\n\n### Customizations\nThis attribute `DisplayCollections` can be used to control the behavior of the `ToString()` method when it is called on collection types that implement `IEnumerable` interface.\n\nWhen the value of the `DisplayCollections` attribute is set to `true`, `ToString()` method will return a string representation of the collection's elements, separated by a comma. This allows for easy visualization of the contents of the collection.\n\nIf the `DisplayCollections` attribute is not specified, or if its value is set to `false`, `ToString()` method will return the name of type of the collection. This is the default behavior.\n\n### How to activate\n\nJust do two things. Mark your class as `partial` and add my attribute `[ToString]`.","funding_links":[],"categories":["Source Generators","Do not want to test 112 ( old ISourceGenerator )"],"sub_categories":["Other","1. [ThisAssembly](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ThisAssembly) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBurgyn%2FMMLib.ToString","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBurgyn%2FMMLib.ToString","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBurgyn%2FMMLib.ToString/lists"}