{"id":13629659,"url":"https://github.com/Youssef1313/PrintMembersGenerator","last_synced_at":"2025-04-17T09:35:34.900Z","repository":{"id":100186143,"uuid":"298400644","full_name":"Youssef1313/PrintMembersGenerator","owner":"Youssef1313","description":"A source generator that helps re-defining C# record's PrintMembers method to force include/exclude certain members.","archived":false,"fork":false,"pushed_at":"2020-09-25T21:59:54.000Z","size":36,"stargazers_count":6,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T19:46:01.508Z","etag":null,"topics":["csharp","csharp-sourcegenerator","printmembers","records","source-generators"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Youssef1313.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-09-24T21:37:42.000Z","updated_at":"2024-06-18T10:56:23.000Z","dependencies_parsed_at":"2023-05-12T18:16:09.168Z","dependency_job_id":null,"html_url":"https://github.com/Youssef1313/PrintMembersGenerator","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/Youssef1313%2FPrintMembersGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Youssef1313%2FPrintMembersGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Youssef1313%2FPrintMembersGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Youssef1313%2FPrintMembersGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Youssef1313","download_url":"https://codeload.github.com/Youssef1313/PrintMembersGenerator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223751349,"owners_count":17196619,"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","csharp-sourcegenerator","printmembers","records","source-generators"],"created_at":"2024-08-01T22:01:15.879Z","updated_at":"2024-11-08T20:31:37.832Z","avatar_url":"https://github.com/Youssef1313.png","language":"C#","readme":"# PrintMembersGenerator\n\nA source generator that helps re-defining C# record's PrintMembers method to force include/exclude certain members.\n\nThis project is related to [dotnet/csharplang#3925](https://github.com/dotnet/csharplang/issues/3925).\n\nFor more information about source generators, see [Introducing C# source generators blog](https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/).\n\n## Overview\n\nC# 9.0 introduced a new language feature called [Records](https://docs.microsoft.com/dotnet/csharp/language-reference/proposals/csharp-9.0/records). A record is simply a reference type with some compiler-generated (synthesized) methods.\n\nThe interest of this project is on `PrintMembers` method, which the compiler uses when you call `.ToString()` on a record.\n\nThe compiler only includes all public non-override instance fields/properties in `PrintMembers`, and allows you to re-define PrintMembers if the provided implementation doesn't suite your need.\n\nThis source generator makes it easier to force-include or force-exclude certain record members in `PrintMembers` implementation through a provided attribute.\n\n## How to use\n\n### Add reference to the generator\n\nCurrently, this is not packed into a NuGet package. So you'll have to clone the source code, and add a reference to the *PrintMembersSourceGenerators.csproj*. The added reference should look like the following:\n\n```xml\n  \u003cItemGroup\u003e\n    \u003cProjectReference Include=\"PATH TO PrintMembersGenerator.csproj\" \n                      OutputItemType=\"Analyzer\"\n                      ReferenceOutputAssembly=\"false\" /\u003e\n  \u003c/ItemGroup\u003e\n```\n\n### Use the attribute\n\nFirst of all, here is the internal definition of the attribute:\n\n```csharp\nnamespace SourceGenerator\n{\n    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]\n    public sealed class PrintMembersAttribute : Attribute\n    {\n        public bool ShouldInclude { get; set; } = true;\n    }\n}\n```\n\nAs you see, the attribute can only be applied to fields and properties.\n\n- To force-include a member in `PrintMembers`, you should either use `[PrintMembers]` or `[PrintMembers(ShouldInclude = true)]`.\n- To force-exclude a member in `PrintMembers`, you should use `[PrintMembers(ShouldInclude = false)]`.\n\nCurrently, positional record parameters are not supported. Support for them should be added soon through targeted attributes:\n\n```csharp\n[property: PrintMembers(ShouldInclude = false)]\n```\n\nSee [this comment on dotnet/csharplang#3644](https://github.com/dotnet/csharplang/issues/3644#issuecomment-692742525).\n\n## Notes\n\n1. If the semantics of the added attribute is the **same** as what the compiler does, the generator ignores the attribute.\n2. The record **must** be partial to allow the source generator to re-define `PrintMembers`.\n","funding_links":[],"categories":["Do not want to test 112 ( old ISourceGenerator )","Source Generators"],"sub_categories":["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","Other"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYoussef1313%2FPrintMembersGenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FYoussef1313%2FPrintMembersGenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYoussef1313%2FPrintMembersGenerator/lists"}