{"id":19121056,"url":"https://github.com/dadhi/csharptypeprinter","last_synced_at":"2025-05-05T16:25:51.139Z","repository":{"id":66273456,"uuid":"295376972","full_name":"dadhi/CSharpTypePrinter","owner":"dadhi","description":"Prints System.Type object as a valid C# literal, e.g. typeof(A\u003cX\u003e.B\u003cY\u003e.C) as a \"A\u003cX\u003e.B\u003cY\u003e.C\"","archived":false,"fork":false,"pushed_at":"2020-10-15T13:19:55.000Z","size":26,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-19T10:28:07.202Z","etag":null,"topics":["automation","code-generation","csharp","dotnet","happiness","pretty-print","reflection","to-string","type"],"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/dadhi.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,"zenodo":null}},"created_at":"2020-09-14T10:07:10.000Z","updated_at":"2023-06-12T11:13:56.000Z","dependencies_parsed_at":"2023-06-14T09:30:35.815Z","dependency_job_id":null,"html_url":"https://github.com/dadhi/CSharpTypePrinter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadhi%2FCSharpTypePrinter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadhi%2FCSharpTypePrinter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadhi%2FCSharpTypePrinter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadhi%2FCSharpTypePrinter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dadhi","download_url":"https://codeload.github.com/dadhi/CSharpTypePrinter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252532815,"owners_count":21763475,"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":["automation","code-generation","csharp","dotnet","happiness","pretty-print","reflection","to-string","type"],"created_at":"2024-11-09T05:15:56.422Z","updated_at":"2025-05-05T16:25:51.133Z","avatar_url":"https://github.com/dadhi.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSharpTypePrinter\n\n[![NuGet Badge](https://buildstats.info/nuget/CSharpTypePrinter)](https://www.nuget.org/packages/CSharpTypePrinter)[![fuget.org](https://www.fuget.org/packages/CSharpTypePrinter/badge.svg?v=1.0.0)](https://www.fuget.org/packages/CSharpTypePrinter/1.0.0/)\n\nTargets **.NET Standard 2.0**\n\nPrints a `System.Type` object as a valid C# literal, e.g. prints `typeof(A\u003cX\u003e.B\u003cY\u003e.C)` as a `\"A\u003cX\u003e.B\u003cY\u003e.C\"`\n\nIt happens that the code for this is the complex pile of details especially if we talk about nested generics.\n\nSo I wanted to automate it and get and the robust implementation. A similar code is used Today by three of my projects: [DryIoc](https://github.com/dadhi/DryIoc), [FastExpressionCompiler](https://github.com/dadhi/FastExpressionCompiler), [ImTools](https://github.com/dadhi/ImTools).\n\nThe library contains a single extension method: \n\n```cs\npublic static class TypePrinter \n{\n    public static string ToCSharpCode(this Type type,\n        bool stripNamespace = false, \n        Func\u003cType, string, string\u003e printType = null, \n        bool printGenericTypeArgs = false) \n        { \n            //:-)\n        }\n}\n```\n\nThe options include:\n\n- `stripNamespace` self explanatory.\n- `printType` function may configure the final result given the input type and the output string.\n- `printGenericTypeArgs` if set to true will output open-generic type as `Blah\u003cT\u003e` instead of `Blah\u003c\u003e`. The default value is false because of my own use-case of the type inside the `typeof()` where `typeof(Blah\u003c\u003e)` is the valid code and the `typeof(Blah\u003cT\u003e)` is not.\n\n\nHappy coding! \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdadhi%2Fcsharptypeprinter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdadhi%2Fcsharptypeprinter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdadhi%2Fcsharptypeprinter/lists"}