{"id":21721069,"url":"https://github.com/anderly/expansive","last_synced_at":"2025-08-08T13:18:16.111Z","repository":{"id":140076577,"uuid":"2550795","full_name":"anderly/Expansive","owner":"anderly","description":"A powerful string expansion library for .NET you never knew you always wanted.","archived":false,"fork":false,"pushed_at":"2014-11-03T15:46:26.000Z","size":232,"stargazers_count":35,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-12T09:18:03.070Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://nuget.org/List/Packages/Expansive","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/anderly.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}},"created_at":"2011-10-10T20:28:02.000Z","updated_at":"2023-01-15T20:29:42.000Z","dependencies_parsed_at":"2023-03-12T17:30:18.317Z","dependency_job_id":null,"html_url":"https://github.com/anderly/Expansive","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/anderly%2FExpansive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderly%2FExpansive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderly%2FExpansive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderly%2FExpansive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anderly","download_url":"https://codeload.github.com/anderly/Expansive/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248636808,"owners_count":21137527,"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-11-26T02:13:41.937Z","updated_at":"2025-04-12T21:33:46.916Z","avatar_url":"https://github.com/anderly.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Expansive\n[![Nuget version](http://img.shields.io/nuget/v/expansive.svg?style=flat)](http://www.nuget.org/Packages/Expansive)\n[![License](http://img.shields.io/badge/license-MS--PL-red.svg?style=flat)](http://opensource.org/licenses/MS-PL)\n### A powerful string expansion library for .NET you never knew you always wanted.\n\n### View the [Release Notes](https://github.com/anderly/Expansive/blob/master/ReleaseNotes.md) to see change history.\n\n## Why do I need it?\n\nConfig settings, string.Format, email, SMS, push notifications, Facebook posts, Twitter posts, reports, the list goes on.\n\nWe work with strings every day and it isn't fun. **Expansive** changes that by making your strings readable, intuitive, smart and...expandable!\n\n## How would I use it?\n\n- Use as a more readable alternative to string.Format()\n- Easily embed tokens in strings and expand them easily.\n- Chain together tokens to reduce redundant values.\n- Simple templating for emails, SMS, push notifications, Facebook posts, Twitter posts, reports, etc.\n- Use your imagination.\n\n## Features\n\n* Uses a Func\u003cstring,string\u003e lambda factory method as the source for token lookup/expansion\n* By default string tokens are expanded using ConfigurationManager.AppSettings as the source (change this to your liking)\n* Dynamic ConfigurationManager wrapper called Config wraps the Expansive API and removes need to call Expand()\n* Register your own Func\u003cstring,string\u003e ExpansionFactory as the default string expansion factory or specify on the call to Expand()\n* 4 Token Style Formats to pick from:\n - MvcRoute Style \"{token}\" (default)\n - Razor Style    \"@token\" or \"@(token)\"\n - NAnt Style     \"${token}\"\n - MSBuild Style  \"$(token)\"\n* Set your TokenStyle format globally or on a per call basis on the call to Expand()\n* Support for chained expansions from one token to another\n\n## How do I install it?\n\nUsing NuGet:\n\n\tInstall-Package Expansive\n\t\n**OR**\n\nSimply drop the code into your app and change it as you wish.\n\n## Show me the code\n\n### Simple readable alternative to string.Format() using Func\u0026lt;string, string\u0026gt; lamda\n\n**MvcRoute-style token**\n\n\t\"Hello, {name}\".Expand(n =\u003e \"John\")\n\t// returns \"Hello, John\"\n\t\n**Razor-style token**\n\n\t\"Hello, @name\".Expand(n =\u003e \"John\")\n\t// returns \"Hello, John\"\n\t\nor\n\t\n\t\"Hello, @(name)\".Expand(n =\u003e \"John\")\n\t// returns \"Hello, John\"\n\t\n**NAnt-style token**\n\n\t\"Hello, ${name}\".Expand(n =\u003e \"John\")\n\t// returns \"Hello, John\"\n\t\n**MSBuild-style token**\n\n\t\"Hello, $(name)\".Expand(n =\u003e \"John\")\n\t// returns \"Hello, John\"\n\t\n### Simple readable alternative to string.Format() using positional replacement\n\n**One token (MvcRoute-style)**\n\n\t\"Hello, {name}\".Expand(\"John\")\n\t// returns \"Hello, John\"\n\t\n**Two tokens (MvcRoute-style)**\n\n\t\"Hello, {firstName} {lastName}\".Expand(\"John\",\"Smith\")\n\t// returns \"Hello, John Smith\"\n\t\n**3 tokens (MvcRoute-style), 2 single tokens, 1 composite token**\n\n\tvar firstName = \"John\";\n\tvar lastName = \"Smith\";\n\tvar fullName = \"{firstName} {lastName}\";\n\t\"Your first name is {firstName}. Your last name is {lastName}. Your full name is {fullName}\".Expand(fullName, lastName, fullName)\n\t// returns \"Your first name is John. Your last name is Smith. Your full name is John Smith\"\n\n### Simple Example (using AppSettings as default source for token expansion)\n\nIn app.config:\n\n\t\u003cconfiguration\u003e\n\t\t\u003cappSettings\u003e\n\t\t\t\u003cadd key=\"KeyForAppSetting1\" value=\"ValueForAppSetting1\"/\u003e\n\t\t\u003c/appSettings\u003e\n\t\u003c/configuration\u003e\n\nUse the **.Expand()** extension method explicitly on the string to be expanded:\n\n\t\"{KeyForAppSetting1} should be inserted here.\".Expand();\n\t// returns \"ValueForAppSetting1 should be inserted here.\"\n\t\n### Moderate Example (using AppSettings as default source for token expansion)\n\nIn app.config:\n\n\t\u003cconfiguration\u003e\n\t\t\u003cappSettings\u003e\n\t\t\t\u003cadd key=\"Domain\" value=\"mycompany.com\"/\u003e\n\t\t\t\u003cadd key=\"ServerName\" value=\"db01.{Domain}\"/\u003e\n\t\t\u003c/appSettings\u003e\n\t\t\u003cconnectionStrings\u003e\n\t\t\t\u003cadd name=\"Default\" connectionString=\"server={ServerName};uid=uid;pwd=pwd;Initial Catalog=master;\" provider=\"System.Data.SqlClient\" /\u003e\n\t\t\u003c/connectionStrings\u003e\n\t\u003c/configuration\u003e\n\nUse the **.Expand()** extension method on the string to be expanded:\n\n\tvar connectionString = ConfigurationManager.ConnectionStrings[\"Default\"].ConnectionString;\n\tconnectionString.Expand() // returns \"server=db01.mycompany.com;uid=uid;pwd=pwd;Initial Catalog=master;\"\n\nor\n\nUse the Dynamic ConfigurationManager wrapper \"Config\" as follows (Explicit call to Expand() not necessary):\n\n\tvar serverName = Config.AppSettings.ServerName;\n\t// returns \"db01.mycompany.com\"\n\t\n\tvar connectionString = Config.ConnectionStrings.Default;\n\t// returns \"server=db01.mycompany.com;uid=uid;pwd=pwd;Initial Catalog=master;\"\n\t\n### Advanced Example 1 (using AppSettings as default source for token expansion)\n\nIn app.config:\n\n\t\u003cconfiguration\u003e\n\t\t\u003cappSettings\u003e\n\t\t\t\u003cadd key=\"Environment\" value=\"dev\"/\u003e\n\t\t\t\u003cadd key=\"Domain\" value=\"mycompany.com\"/\u003e\n\t\t\t\u003cadd key=\"UserId\" value=\"uid\"/\u003e\n\t\t\t\u003cadd key=\"Password\" value=\"pwd\"/\u003e\n\t\t\t\u003cadd key=\"ServerName\" value=\"db01-{Environment}.{Domain}\"/\u003e\n\t\t\t\u003cadd key=\"ReportPath\" value=\"\\\\{ServerName}\\SomeFileShare\"/\u003e\n\t\t\u003c/appSettings\u003e\n\t\t\u003cconnectionStrings\u003e\n\t\t\t\u003cadd name=\"Default\" connectionString=\"server={ServerName};uid={UserId};pwd={Password};Initial Catalog=master;\" provider=\"System.Data.SqlClient\" /\u003e\n\t\t\u003c/connectionStrings\u003e\n\t\u003c/configuration\u003e\n\t\nUse the .Expand() extension method on the string to be expanded:\n\n\tvar connectionString = ConfigurationManager.ConnectionStrings[\"Default\"].ConnectionString;\n\tconnectionString.Expand() // returns \"server=db01-dev.mycompany.com;uid=uid;pwd=pwd;Initial Catalog=master;\"\n\t\n### Advanced Example 2 (using custom Func\u003cstring,string\u003e lambda as default source for token expansion)\n\n\tvar tokenValueDictionary = new Dictionary\u003cstring, string\u003e {\n\t\t{\"setting1\",\"The quick\"}\n\t\t,{\"setting2\",\"{setting1} brown fox\"}\n\t\t,{\"setting3\",\"jumped over\"}\n\t\t,{\"setting4\",\"{setting2} {setting3} the lazy dog.\"}\n\t\t,{\"setting5\",\"{setting4}\"}\n\t};\n\n\tExpansive.DefaultExpansionFactory = name =\u003e tokenValueDictionary[name];\n\n\tConsole.WriteLine(\"{setting5}\".Expand());\n\t//returns \"The quick brown fox jumped over the lazy dog.\"\n\t\n\tor\n\t\n\t// Here, we specify the token expansion factory on the call to Expand()\n\tConsole.WriteLine(\"{setting5}\".Expand(name =\u003e tokenValueDictionary[name]));\n\t//returns \"The quick brown fox jumped over the lazy dog.\" \n\n### Simple model-based string templating\n\n\tvar model = new { FirstName = \"John\" };\n\n\t// MvcRoute-Style (default)\n\tvar mvcRouteStyleString = \"Hello, {FirstName}\".Expand(model);\n\n\t// Razor-Style\n\tExpansive.DefaultTokenStyle = TokenStyle.Razor;\n\tvar razorStyleString = \"Hello, @FirstName\".Expand(model);\n\n\t// NAnt-Style\n\tExpansive.DefaultTokenStyle = TokenStyle.NAnt;\n\tvar nantStyleString = \"Hello, ${FirstName}\".Expand(model);\n\n\t// MSBuild-Style\n\tExpansive.DefaultTokenStyle = TokenStyle.MSBuild;\n\tvar msBuildStyleString = \"Hello, $(FirstName)\".Expand(model);\n\n\t// All return \"Hello, John\"\n\t\n### Moderate model-based string templating\n\n\tvar model = new { \n\t\tFirstName = \"John\",\n\t\tLastName = \"Smith\",\n\t\tFullName = \"{FirstName} {LastName}\"\n\t};\n\n\t\"FullName:{FullName}\".Expand(model);\n\t// Returns \"FullName:John Smith\"\n\t\n### Advanced multi-model string templating\n\n\tvar model1 = new { \n\t\tFirstName = \"John\",\n\t\tLastName = \"Smith\",\n\t\tFullName = \"{FirstName} {LastName}\"\n\t};\n\t\n\tvar model2 = new {\n\t\tEmailAddress = \"john.smith@gmail.com\"\n\t};\n\n\t\"FullName:{FullName} ({EmailAddress})\".Expand(model1, model2);\n\t// Returns \"FullName:John Smith (john.smith@gmail.com)\"\n\n## Copyright\n\nCopyright 2011 Adam Anderly\n\n## License\n\nMS-PL: http://www.opensource.org/licenses/MS-PL\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanderly%2Fexpansive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanderly%2Fexpansive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanderly%2Fexpansive/lists"}