{"id":23819787,"url":"https://github.com/eposgmbh/epos.foundation","last_synced_at":"2026-03-06T20:03:43.451Z","repository":{"id":65413788,"uuid":"106425628","full_name":"eposgmbh/Epos.Foundation","owner":"eposgmbh","description":"Epos.Foundation - .NET Standard utilities and other foundational stuff.","archived":false,"fork":false,"pushed_at":"2024-05-11T07:25:07.000Z","size":11567,"stargazers_count":1,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-15T20:22:41.345Z","etag":null,"topics":["arithmetics","command-line-parser","csharp","csharp-library","di-container","dotnet","dotnet-standard","dotnetcore","utilities"],"latest_commit_sha":null,"homepage":"https://eposgmbh.github.io/getting-started.html","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/eposgmbh.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}},"created_at":"2017-10-10T14:06:24.000Z","updated_at":"2024-05-11T07:25:11.000Z","dependencies_parsed_at":"2023-01-23T10:55:05.691Z","dependency_job_id":"749fe0db-21e7-4711-b338-ddd2c9882726","html_url":"https://github.com/eposgmbh/Epos.Foundation","commit_stats":{"total_commits":57,"total_committers":2,"mean_commits":28.5,"dds":0.03508771929824561,"last_synced_commit":"e8eaca6d2e4c911d430c8d1e0195bbfc1372d111"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eposgmbh%2FEpos.Foundation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eposgmbh%2FEpos.Foundation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eposgmbh%2FEpos.Foundation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eposgmbh%2FEpos.Foundation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eposgmbh","download_url":"https://codeload.github.com/eposgmbh/Epos.Foundation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232163094,"owners_count":18481581,"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":["arithmetics","command-line-parser","csharp","csharp-library","di-container","dotnet","dotnet-standard","dotnetcore","utilities"],"created_at":"2025-01-02T07:15:18.121Z","updated_at":"2026-03-06T20:03:43.435Z","avatar_url":"https://github.com/eposgmbh.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Epos.Foundation\n\n![Build Status](https://eposgmbh.visualstudio.com/_apis/public/build/definitions/30ebff28-f13c-44d2-b6db-7739d6cf4ab1/5/badge)\n[![NuGet](https://img.shields.io/nuget/v/Epos.Utilities.svg)](https://www.nuget.org/packages/Epos.Utilities/)\n![License](https://img.shields.io/badge/license-MIT-blue.svg)\n![Downloads](https://img.shields.io/nuget/dt/Epos.Utilities.svg)\n\nBuild and Release deployment (Docs Website and [NuGet](https://www.nuget.org/)) is automated with\n[Azure DevOps](https://dev.azure.com).\n\n## Docs\n\nEpos.Foundation is the Github Repo for foundational utilities like String or Dictionary extension methods\n(NuGet package **Epos.Utilities**), utilities for web apps and web APIs (NuGet package **Epos.Utilities.Web**) and a powerful and simple command line parser (NuGet package **Epos.CommandLine**).\n\nThe packages are implemented using .NET 8+. Therefore you can use them cross-platform on any supported platform.\n\n[See the Docs Website.](https://eposgmbh.github.io/getting-started.html)\n\n## Installation\n\nVia NuGet you can install the following NuGet packages:\n\n```bash\n$ dotnet add package Epos.Utilities\n$ dotnet add package Epos.Utilities.Web\n$ dotnet add package Epos.CommandLine\n$ dotnet add package Epos.TestUtilities\n```\n\nYou can install them separately, the packages are independent from each other.\n\n## Usage\n\n**Epos.Utilities** and **Epos.Utilities.Web** are more or less self-documenting simple utility classes. You can take a\nlook at the corresponding unit tests in [this Github Repo](https://github.com/eposgmbh/Epos.Foundation/tree/master/src/Epos.Utilities.Tests).\n\n**Epos.TestUtilities** allows spinning up Docker containers for integration or unit test runs. See the corresponging unit tests in [this Github Repo](https://github.com/eposgmbh/Epos.Foundation/tree/master/src/Epos.TestUtilities.Tests).\n\n**Epos.CommandLine** is a full fledged yet simple command line parser. Source code for a demo console app can be found in\n[this Github Repo](https://github.com/eposgmbh/Epos.Foundation/tree/master/src/Epos.CommandLine.Sample).\n\n### Epos.Utilities\n\nHighlights of the **Epos.Utilities** package are:\n\n#### Arithmetics\n\nUse the `Arithmetics` class to do generic calculations for different data types like\n`int` or `double`:\n\n```csharp\ndouble theDouble = Arithmetics.GetZeroValue\u003cdouble\u003e(); // 0.0\nint theInteger = Arithmetics.GetOneValue\u003cint\u003e(); // 1\n\nvar theAddIntegers = Arithmetics.CreateAddOperation\u003cint\u003e();\nint theSum = theAddIntegers(theInteger, 33); // 34\n\nvar theMultiplyDoubles = Arithmetics.CreateMultiplyOperation\u003cdouble\u003e();\ndouble theProduct = theMultiplyDoubles(11.0, 6.5); // 71.5\n```\n\n#### StringExtensions\n\nUse the `StringExtensions` class to do (among other things) generic type conversions\nfrom a string. You can convert to any type with an attached `TypeConverterAttribute`.\n\n```csharp\nbool isSuccess = \"33\".TryConvert(CultureInfo.InvariantCulture, out int theInteger);\nAssert.That(theInteger, Is.EqualTo(33));\nAssert.That(isSuccess, Is.True);\n\n// or equivalent:\n\nisSuccess = \"33\".TryConvert(typeof(int), CultureInfo.InvariantCulture, out object theObject);\nAssert.That(theObject, Is.EqualTo(33));\nAssert.That(isSuccess, Is.True);\n\n// Failure case:\n\nisSuccess = \"ABC\".TryConvert(CultureInfo.InvariantCulture, out double theDouble);\nAssert.That(theDouble, Is.EqualTo(0.0));\nAssert.That(isSuccess, Is.False);\n```\n\n#### DumpExtensions\n\nUse the `DumpExtensions` class to pretty-print any kind of object.\n\n```csharp\n// null values\nobject obj = null;\nConsole.WriteLine(obj.Dump()); // Null\n\n// Types\nConsole.WriteLine(typeof(int).Dump()); // int\nConsole.WriteLine(typeof(double).Dump()); // double\nConsole.WriteLine(typeof(double?).Dump()); // double?\nConsole.WriteLine(typeof(Cache\u003c,\u003e).Dump()); // Epos.Utilities.Cache\u003cTKey, TValue\u003e\n\ndouble dbl = 33.99;\nConsole.WriteLine(dbl.Dump()); // 33.99 (Dump always uses the invariant culture)\n\n// Complex type instances:\nConsole.WriteLine(new[] { 1, 2, 3 }.Dump()); // [1, 2, 3]\nConsole.WriteLine(new { Integer = 1, String = \"Hello\" }.Dump()); // { Integer = 1, String = Hello }\n```\n\n#### Container\n\nUse the `Container` class as a simple lightweight DI Container.\n\n```csharp\nvar theContainer = new Container();\ntheContainer\n    .Register\u003cITestService\u003e()\n    .ImplementedBy\u003cTestService\u003e()\n    .WithParameter(\"connectionString\", \"Hello World!\") // Constructor params\n    .AndParameter(\"maxCount\", 10)\n    .WithLifetime(Lifetime.Singleton);\n\n// ...\n\nvar theTestService = theContainer.Resolve\u003cITestService\u003e();\n```\n\n### Epos.CommandLine\n\nSample `BuildOptions` class for strongly typed access of the command line parameters:\n\n```csharp\npublic class BuildOptions\n{\n    [CommandLineOption('p')]\n    public int ProjectNumber { get; set; }\n\n    [CommandLineOption('m')]\n    public string Memory { get; set; }\n\n    // ...\n}\n```\n\nSample entry point that uses the `BuildOptions` class for the subcommand `build`:\n\n```csharp\nvar theCommandLineDefinition = new CommandLineDefinition {\n    Configuration = new CommandLineConfiguration {\n        Name = \"sample\", // \u003c- if unset, .exe-Filename is taken\n    },\n    Subcommands = {\n        new CommandLineSubcommand\u003cBuildOptions\u003e(\"build\", \"Builds something.\") {\n            Options = {\n                new CommandLineOption\u003cint\u003e('p', \"Sets the project number.\") { LongName = \"project-number\" },\n                new CommandLineOption\u003cstring\u003e('m', \"Sets the used memory.\") {\n                    LongName = \"memory\",\n                    DefaultValue = \"1 GB\"\n                },\n                new CommandLineSwitch('d', \"Disables the command.\"),\n                new CommandLineSwitch('z', \"Zzzz...\")\n            },\n            Parameters = {\n                new CommandLineParameter\u003cstring\u003e(\"filename\", \"Sets the filename.\")\n            },\n            CommandLineFunc = (options, definition) =\u003e {\n                // Do something for the build subcommand\n                // ...\n\n                Console.WriteLine(\"sample command line application\" + Lf);\n                Console.WriteLine(options.Dump() + Lf);\n\n                return 0; // \u003c- your error code or 0, if successful\n            }\n        }\n    },\n    // further subcommands...\n    //\n    // If you don't want to specify subcommands, register one subcommand with the name \"default\"\n    // (or use the constant CommandLineSubcommand.DefaultName) and set the HasDifferentiatedSubcommands\n    // property of the CommandLineDefinition to false.\n};\n\nreturn theCommandLineDefinition.Try(args);\n```\n\nThis simple definition automatically produces help and usage console output like this:\n\n```\nUsage: sample build [-p, --project-number \u003cint\u003e] [-m, --memory \u003cstring=\"1 GB\"\u003e] [-d] [-z] \u003cfilename:string\u003e\n\nError: Missing parameter: filename\n\nOptions\n  -p, --project-number   Sets the project number.\n  -m, --memory           Sets the used memory. \u003e\u003e\u003e defaults to \"1 GB\"\n  -d                     Disables the command.\n  -z                     Zzzz...\n\nParameters\n  filename               Sets the filename.\n```\n\nLong option chains and description texts are properly line breaked regarding the console window width.\n\n---\n\nAlternatively you can use the even simpler and mightier `CommandLineApplicationBuilder` class. It supports logging (to the console of course, but you can register further loggers or provide your own implementation) and dependency injection (see `TestService`) for the sub commands.\n\nThe subcommands are registered with the `AddSubcommand` method, see below for an example with just one `default` subcommand (which means no subcommand at all).\n\n```csharp\nusing Epos.CommandLine.Application;\n\nHostApplicationBuilder theBuilder = CommandLineApplicationBuilder.CreateApplicationBuilder(args);\n\ntheBuilder.Configure(x =\u003e {\n    x.Name = \"test-app\";\n});\n\ntheBuilder.Services.AddSingleton\u003cTestService\u003e();\ntheBuilder.Services.AddSubcommand\u003cMySubcommand\u003e();\n\nawait theBuilder\n    .Build()\n    .RunAsync();\n\n// ---------------------------------------------\n\nclass TestService\n{\n    public string GetSomeString() =\u003e \"Hello, World!\";\n}\n\nclass MySubcommand(TestService testService, ILogger\u003cMySubcommand\u003e logger) : ISubcommand\n{\n    public string Name =\u003e \"default\";\n\n    public string Description =\u003e \"Default command\";\n\n    [Option('t', \"Test option\", LongName = \"test\")]\n    public string? TestOption { get; set; }\n\n    [Parameter(\"test-param\", \"Test parameter\", DefaultValue = 123)]\n    public int TestParam { get; set; }\n\n\n    public Task\u003cint\u003e ExecuteAsync(CancellationToken cancellationToken) {\n        if (TestOption == \"World\" \u0026\u0026\n            testService.GetSomeString().StartsWith(\"Hello\"))\n        {\n            logger.LogInformation(\"Successful!\");\n            return Task.FromResult(TestParam);\n        }\n        else\n        {\n            logger.LogError(\"Unsuccessful!\");\n            return Task.FromResult(0);\n        }\n    }\n}\n```\n\nIf you just need to write text to the console, use the `LogInformation` method (you may use `Console.WriteLine` alternatively). Other log levels produce `WARNING`-, `ERROR`- etc. banners. For `INFO`-banner use `LogTrace`.\n\n## Contributing\n\nYou can enter an issue on Github [here](https://github.com/eposgmbh/Epos.Foundation/issues). I will work on\nyour issue when I have time. Pull Requests are possible too.\n\n## License\n\nMIT License\n\nCopyright (c) 2017-2024 eposgmbh\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feposgmbh%2Fepos.foundation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feposgmbh%2Fepos.foundation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feposgmbh%2Fepos.foundation/lists"}