{"id":15475171,"url":"https://github.com/vsajip/dotnet-cfg-lib","last_synced_at":"2026-05-13T02:32:46.330Z","repository":{"id":54713863,"uuid":"250178158","full_name":"vsajip/dotnet-cfg-lib","owner":"vsajip","description":"A CLR library for working with the CFG configuration format.","archived":false,"fork":false,"pushed_at":"2025-01-10T11:50:08.000Z","size":358,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T20:37:30.165Z","etag":null,"topics":["configuration","csharp","dotnet"],"latest_commit_sha":null,"homepage":"https://docs.red-dove.com/cfg/index.html","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/vsajip.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-03-26T06:24:56.000Z","updated_at":"2025-01-10T11:50:11.000Z","dependencies_parsed_at":"2022-08-14T00:40:40.933Z","dependency_job_id":null,"html_url":"https://github.com/vsajip/dotnet-cfg-lib","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/vsajip%2Fdotnet-cfg-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsajip%2Fdotnet-cfg-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsajip%2Fdotnet-cfg-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsajip%2Fdotnet-cfg-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vsajip","download_url":"https://codeload.github.com/vsajip/dotnet-cfg-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241637645,"owners_count":19995012,"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":["configuration","csharp","dotnet"],"created_at":"2024-10-02T03:07:54.200Z","updated_at":"2026-05-13T02:32:46.299Z","avatar_url":"https://github.com/vsajip.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"The CFG configuration format is a text format for configuration files which is similar to, and a superset of, the JSON format. It dates from before its first announcement in [2008](https://wiki.python.org/moin/HierConfig) and has the following aims:\n\n* Allow a hierarchical configuration scheme with support for key-value mappings and lists.\n* Support cross-references between one part of the configuration and another.\n* Provide a string interpolation facility to easily build up configuration values from other configuration values.\n* Provide the ability to compose configurations (using include and merge facilities).\n* Provide the ability to access real application objects safely, where supported by the platform.\n* Be completely declarative.\n\nIt overcomes a number of drawbacks of JSON when used as a configuration format:\n\n* JSON is more verbose than necessary.\n* JSON doesn’t allow comments.\n* JSON doesn’t provide first-class support for dates and multi-line strings.\n* JSON doesn’t allow trailing commas in lists and mappings.\n* JSON doesn’t provide easy cross-referencing, interpolation, or composition.\n\nInstallation\n============\nThe library can be installed using `nuget` and the package name `RedDove.Config`.\n\nExploration\n============\nTo explore CFG functionality for .NET, we use the `dotnet-script` Read-Eval-Print-Loop (REPL), which is available from [here](https://github.com/filipw/dotnet-script). Once installed, you can invoke a shell using\n```\n$ dotnet dotnet-script\n```\n\nGetting Started with CFG in C#\n==============================\nA configuration is represented by an instance of the `Config` struct. The constructor for this class can be passed a filename or a stream which contains the text for the configuration. The text is read in, parsed and converted to an object that you can then query. A simple example:\n\n```\na: 'Hello, '\nb: 'world!'\nc: {\n  d: 'e'\n}\n'f.g': 'h'\nchristmas_morning: `2019-12-25 08:39:49`\nhome: `$HOME`\nfoo: `$FOO|bar`\n```\n\nLoading a configuration\n=======================\nThe configuration above can be loaded as shown below. In the REPL shell:\n\n```\n\u003e #r \"RedDove.Config.dll\"\n\u003e using RedDove.Config;\n\u003e var cfg = new Config(\"test0a.cfg\");\n\u003e cfg[\"a\"]\n\"Hello, \"\n\u003e cfg[\"b\"]\n\"world!\"\n```\n\nAccess elements with keys\n=========================\nAccessing elements of the configuration with a simple key is just like using a `Dictionary\u003cstring, object\u003e`:\n\n```\n\u003e cfg[\"a\"]\n\"Hello, \"\n\u003e cfg[\"b\"]\n\"world!\"\n```\nYou can see the types and values of the returned objects are as expected.\n\nAccess elements with paths\n==========================\nAs well as simple keys, elements  can also be accessed using `path` strings:\n```\n\u003e cfg[\"c.d\"]\n\"e\"\n```\nHere, the desired value is obtained in a single step, by (under the hood) walking the path `c.d` – first getting the mapping at key `c`, and then the value at `d` in the resulting mapping.\n\nNote that you can have simple keys which look like paths:\n```\n\u003e cfg[\"f.g\"]\n\"h\"\n```\nIf a key is given that exists in the configuration, it is used as such, and if it is not present in the configuration, an attempt is made to interpret it as a path. Thus, `f.g` is present and accessed via key, whereas `c.d` is not an existing key, so is interpreted as a path.\n\nAccess to date/time objects\n===========================\nYou can also get native CLR `System.DateTime` and `System.DateTimeOffset` objects from a configuration, by using an ISO date/time pattern in a `backtick-string`:\n```\n\u003e cfg[\"christmas_morning\"]\n[25/12/2019 08:39:49]\n```\n\nAccess to other CLR objects\n===========================\nAccess to other CLR objects is also possible using the backtick-string syntax, provided that they are either environment values or objects accessible via public static fields, properties or methods which take no arguments:\n```\n\u003e cfg[\"access\"]\nReadWrite\n\u003e cfg[\"today\"]\n[15/01/2020 00:00:00]\n```\n\nAccess to environment variables\n===============================\n\nTo access an environment variable, use a `backtick-string` of the form `$VARNAME`:\n```\n\u003e cfg[\"home\"].Equals(Environment.GetEnvironmentVariable(\"HOME\"))\ntrue\n```\nYou can specify a default value to be used if an environment variable isn’t present using the `$VARNAME|default-value` form. Whatever string follows the pipe character (including the empty string) is returned if `VARNAME` is not a variable in the environment.\n```\n\u003e cfg[\"foo\"]\n\"bar\"\n```\nFor more information, see [the CFG documentation](https://docs.red-dove.com/cfg/index.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsajip%2Fdotnet-cfg-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvsajip%2Fdotnet-cfg-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsajip%2Fdotnet-cfg-lib/lists"}