{"id":18009901,"url":"https://github.com/kekyo/namingformatter","last_synced_at":"2025-03-26T14:31:36.325Z","repository":{"id":84090090,"uuid":"50437591","full_name":"kekyo/NamingFormatter","owner":"kekyo","description":"Can apply .NET format-string use named key-value arguments.","archived":false,"fork":false,"pushed_at":"2024-09-15T13:28:55.000Z","size":1276,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T03:48:47.424Z","etag":null,"topics":["dotnet","dynamic","string","string-formatting","string-interpolation","string-manipulation"],"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/kekyo.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}},"created_at":"2016-01-26T15:23:16.000Z","updated_at":"2024-09-15T13:28:47.000Z","dependencies_parsed_at":"2023-03-22T17:52:28.984Z","dependency_job_id":"295b072c-c06d-47ad-8990-5540168eacf8","html_url":"https://github.com/kekyo/NamingFormatter","commit_stats":null,"previous_names":["kekyo/namingformatter","kekyo/centerclr.namingformatter"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kekyo%2FNamingFormatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kekyo%2FNamingFormatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kekyo%2FNamingFormatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kekyo%2FNamingFormatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kekyo","download_url":"https://codeload.github.com/kekyo/NamingFormatter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245670739,"owners_count":20653413,"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":["dotnet","dynamic","string","string-formatting","string-interpolation","string-manipulation"],"created_at":"2024-10-30T02:11:31.274Z","updated_at":"2025-03-26T14:31:35.980Z","avatar_url":"https://github.com/kekyo.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# NamingFormatter\n\n![NamingFormatter](https://raw.githubusercontent.com/kekyo/NamingFormatter/master/Images/NamingFormatter.128.png)\n\n## Status\n\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n\n| |Build|NuGet|\n|:----|:----|:----|\n|master|[![NamingFormatter CI build (master)](https://github.com/kekyo/NamingFormatter/workflows/.NET/badge.svg?branch=master)](https://github.com/kekyo/NamingFormatter/actions)|[![NuGet NamingFormatter (master)](https://img.shields.io/nuget/v/NamingFormatter.svg?style=flat)](https://www.nuget.org/packages/NamingFormatter)|\n|devel|[![NamingFormatter CI build (master)](https://github.com/kekyo/NamingFormatter/workflows/.NET/badge.svg?branch=master)](https://github.com/kekyo/NamingFormatter/actions)|[![MyGet NamingFormatter (devel)](https://img.shields.io/myget/kekyo/v/NamingFormatter.svg?style=flat\u0026label=myget)](https://www.myget.org/feed/kekyo/package/nuget/NamingFormatter)|\n\n## What is this?\n\n* NamingFormatter is extended System.String.Format method on .NET.\n* Standard Format method required numbering indexed place-holder.\n  * You probably understand this:\n\n``` csharp\n// C# String interporation style:\n// (These argument variables fixedup at compile time)\nvar formatted =\n    $\"Index0:{arg0}, Index1:{arg1}\";\n\n// Old school style:\nvar formatted = string.Format(\n    \"Index0:{0}, Index1:{1}\",\n    arg0,\n    arg1);\n```\n\n* NamingFormatter can use named key-value arguments, and will fixup at runtime. For example:\n\n``` csharp\nvar keyValues = new Dictionary\u003cstring, object\u003e\n{\n    { \"lastName\", \"Matsui\" },\n    { \"firstName\", \"Kouji\" },\n    { \"foo\", \"bar\" },\n};\nvar formatted = Named.Format(\n    \"FirstName:{firstName}, LastName:{lastName}\",\n    keyValues);\n```\n\n* Of course, we can use the format options.\n\n``` csharp\nvar keyValues = new Dictionary\u003cstring, object\u003e\n{\n    { \"date\", DateTime.Now },\n    { \"value\", 123.456 },\n    { \"foo\", \"bar\" },\n};\nvar formatted = Named.Format(\n    \"Date:{date:R}, Value:{value:E}\",\n    keyValues);\n```\n\n* We can use easier with tuple expression:\n\n``` csharp\nvar formatted = Named.Format(\n    \"Date:{date:R}, Value:{value:E}\",\n    ( \"date\", DateTime.Now ),\n    ( \"value\", 123.456 ),\n    ( \"foo\", \"bar\" ));\n```\n\n## Features\n\n* Easy standard replacement from System.String.Format method.\n* TextWriter version included (WriteFormat extension method). And has asynchronous method overloads (Task).\n* Many variation overloads (Dictionary, IReadOnlyDictionary, Predicate delegate, Selector delegate, IFormatProvider, KeyValuePair and ValueTuple with variable length parameters).\n* Can use structual-key, traverse both public properties and fields.\n* Applied C# nullable-reference type attribtues.\n\n## Benefits\n\n* Flexible argument matching. Useful dynamic interpretation.\n* Format string human-readable/customizable improvement.\n\n## Environments\n\n* .NET 8 to 5\n* .NET Standard 1.0, 2.0, 2.1 (Will effect .NET Core 1.0-3.1)\n* .NET Framework 3.5, 4.0 with client profile, 4.5 to 4.8.1\n\n## How to use\n\n* Search NuGet package and install [\"NamingFormatter\"](https://www.nuget.org/packages/NamingFormatter).\n* View more sample:\n\n``` csharp\nusing NamingFormatter;\n\n// Mostly standard key-value combination in manually.\n// We can use with tuples (excepts net35-client and net40-client).\nvar formatted = Named.Format(\n    \"Date:{date:R}, Value:{value:E}, Name:{name}\",\n    (\"value\", 123.456),\n    (\"name\", \"Kouji\"),\n    (\"date\", DateTime.Now));\n```\n\n``` csharp\nusing NamingFormatter;\n\n// All overloads have an optional fallback delegate.\n// You can handle unknown key identity when the format string contains it.\n// (Default behavior will throw exception)\nvar formatted = Named.Format(\n    \"Date:{date}, Value:{VALUE}, Name:{name}\",\n    key =\u003e \"***\",      // fallback delegate makes safer from exceptions.\n    (\"value\", 123.456),\n    (\"name\", \"Kouji\"),\n    (\"date\", DateTime.Now));\n```\n\n``` csharp\nusing NamingFormatter;\n\n// Structual-key (Traverse properties and fields by dot-notation)\nvar formatted = Named.Format(\n    \"TOD-Millisec:{date.TimeOfDay.TotalMilliseconds}\",\n    (\"date\", DateTime.Now));\n```\n\n``` csharp\nusing NamingFormatter;\n\n// Produce Key-value combination in the Dictionary class.\nvar kvs = new Dictionary\u003cstring, object?\u003e()\n{\n    {\"value\", 123.456},\n    {\"name\", \"Kouji\"},\n    {\"date\", DateTime.Now},\n};\nvar formatted = Named.Format(\n    \"Date:{date:R}, Value:{value:E}, Name:{name}\",\n    kvs);\n```\n\n``` csharp\nusing NamingFormatter;\n\n// Format to TextWriter.\nvar sw = new StreamWriter(stream);\nsw.WriteFormat(\n    \"Date:{date:R}, Value:{value:E}, Name:{name}\",\n    (\"value\", 123.456),\n    (\"name\", \"Kouji\"),\n    (\"date\", DateTime.Now));\nsw.Flush();\n\n// Format to TextWriter with async-await\nvar sw = new StreamWriter(stream);\nawait sw.WriteFormatAsync(\n    \"Date:{date:R}, Value:{value:E}, Name:{name}\",\n    (\"value\", 123.456),\n    (\"name\", \"Kouji\"),\n    (\"date\", DateTime.Now));\nawait sw.FlushAsync();\n```\n\n``` csharp\nusing NamingFormatter;\n\n// Full-interactive (callback) format.\nvar formatted = Named.Format(\n    \"Date:{date:R}, Value:{value:E}, Name:{name}\",\n    key =\u003e key switch\n    {\n        \"name\" =\u003e \"Kouji\";\n        \"date\" =\u003e DateTime.Now;\n        \"value\" =\u003e 123.456;\n        _ =\u003e throw new FormatException();\n    });\n```\n\n``` csharp\nusing NamingFormatter;\n\n// IFormatProvider supported.\nvar formatted = Named.Format(\n    new CultureInfo(\"fr-FR\"),\n    \"Date:{date:R}, Value:{value:E}, Name:{name}\",\n    (\"value\", 123.456),\n    (\"name\", \"Kouji\"),\n    (\"date\", DateTime.Now));\n```\n\n``` csharp\nusing NamingFormatter;\n\n// Easy parametric helper\n// (Named.Pair() method will generate KeyValuePair\u003cstring, object?\u003e)\nvar formatted = Named.Format(\n    \"Date:{date:R}, Value:{value:E}, Name:{name}\",\n    Named.Pair(\"value\", 123.456),\n    Named.Pair(\"name\", \"Kouji\"),\n    Named.Pair(\"date\", DateTime.Now));\n```\n\n``` csharp\nusing NamingFormatter;\n\n// You can use custom bracket definition,\n// when requires changing both your start and end bracket character instead of '{ ... }':\nvar kvs = new Dictionary\u003cstring, object?\u003e()\n{\n    {\"value\", 123.456},\n    {\"name\", \"Kouji\"},\n    {\"date\", DateTime.Now},\n};\nvar formatted = Named.Format(\n    \"Date:{date:R}, Value:{value:E}, Name:{name}\",\n    kvs,\n    // Bracket pair: '@[ ... ]@'\n    new FormatOptions(\"@[\", \"]@\"));\n```\n\n\n## TODO\n\n* F# friendly version.\n\n## License\n\n* Copyright (c) 2016-2024 Kouji Matsui\n* Under Apache v2\n\n## History\n\n* 2.4.0:\n  * Added custom bracket feature (Rebuild required).\n* 2.3.0:\n  * Added .NET 8.0 RC2 assembly.\n* 2.2.0:\n  * Added field lookup ability.\n  * Reduced package dependency.\n* 2.1.0:\n  * Added .NET 6.0 assembly.\n  * Added source link attributes.\n* 2.0.22:\n  * Added fallback delegate features.\n  * Included xml documents.\n* 2.0.18:\n  * Added net461 and net47 assemblies because reduce conflict between netstandard2.0.\n* 2.0.17:\n  * Added ValueTuple overloads.\n  * Added asynchronous overloads.\n* 2.0.16:\n  * Fixed not including net35 assembly.\n* 2.0.15:\n  * Breaking change: Changed the NuGet package name from \"NamingFormatter\" to \"NamingFormatter\".\n  * Breaking change: Changed namespace name from \"CenterCLR\" to \"NamingFormatter\".\n  * Added some target frameworks.\n  * Omitted strong-key signing.\n  * Switched and aggregated CI to GitHub Actions.\n* 2.0.0:\n  * Upgraded new MSBuild format and omit PCL versions.\n* 1.1.1:\n  * Fixed via CI (AppVeyor, Fixed RelaxVersioner)\n* 1.1.0:\n  * Add support platform .NET Core (formally \"dnxcore\").\n* 1.0.0:\n  * Omit IFormatProvider method extension attribute.\n* 0.9.6:\n  * Versioning fixed.\n* 0.9.5:\n  * Add nuget package, Support structual-key, Support .NET 2/.NET 3.5.\n* 0.0.0:\n  * Initial commit.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkekyo%2Fnamingformatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkekyo%2Fnamingformatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkekyo%2Fnamingformatter/lists"}