{"id":23050818,"url":"https://github.com/geta/geta-dotnet-extensions","last_synced_at":"2025-08-15T03:31:32.158Z","repository":{"id":42128022,"uuid":"63493454","full_name":"Geta/geta-dotnet-extensions","owner":"Geta","description":null,"archived":false,"fork":false,"pushed_at":"2022-09-23T08:18:37.000Z","size":106,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":25,"default_branch":"master","last_synced_at":"2024-12-13T20:52:16.092Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Geta.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-16T17:00:21.000Z","updated_at":"2021-11-10T14:26:07.000Z","dependencies_parsed_at":"2023-01-18T13:30:36.941Z","dependency_job_id":null,"html_url":"https://github.com/Geta/geta-dotnet-extensions","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geta%2Fgeta-dotnet-extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geta%2Fgeta-dotnet-extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geta%2Fgeta-dotnet-extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geta%2Fgeta-dotnet-extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Geta","download_url":"https://codeload.github.com/Geta/geta-dotnet-extensions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229890100,"owners_count":18140042,"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-12-15T23:38:08.636Z","updated_at":"2024-12-15T23:38:09.162Z","avatar_url":"https://github.com/Geta.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# .NET extensions and helpers library\n\n![Build](http://tc.geta.no/app/rest/builds/buildType:(id:GetaPackages_GetaNetExtensions_00ci),branch:master/statusIcon)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Geta_geta-dotnet-extensions\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Geta_geta-dotnet-extensions)\n[![Platform](https://img.shields.io/badge/Platform-.NET%20Standard%202.0-blue.svg?style=flat)](https://docs.microsoft.com/en-us/dotnet/core/)\n\n## Description\n\nGeta.Net.Extensions package contains common handlers, extension methods and other common utility methods that can be\nshared between multiple projects.\n\n## How to get started?\n\n```\ndotnet add package Geta.Net.Extensions\n```\n\n## Features\n\nFeatures included in package:\n\n### Helpers\n\n- `CultureInfoHelpers`\n    - `Exists(string cultureName)` - Checks if there is a culture by the provided name.\n- `GenerateRandomString`\n    - `GenerateRandomString(int uppercaseChars, int lowerCaseChars, int digits, int symbols)` - Generates a random\n      string.\n- `QueryStringBuilder` - helps to build parametrized URI. Works both with absolute and relative URIs\n    - `Add(string name, string value)` - adds string parameter to URL\n    - `Add(string name, object value)` - adds object parameter to URL\n    - `Remove(string name)` - removes parameter from URL by name\n    - `Toggle(string name, string value)` - adds string parameter to query if it is not already present, otherwise it\n      removes it.\n    - `Toggle(string name, object value)` - adds object type parameter to query if it is not already present, otherwise\n      it removes it.\n    - `ToString()` - generates URL string. If URL is relative then only list of parameters are returned.\n\n`QueryStringBuilder` examples:\n\n```csharp\n// Initialize builder with absolute url and parameters\nvar builder = new QueryStringBuilder(\"http://domain.com/?param=value\");\n// Add second parameter\nbuilder.Add(\"param2\", \"object\");\n// Should return http://domain.com/?param=value\u0026param2=object\nvar url = builder.ToString();\n```\n\n```csharp\n// Initialize builder with relative url and parameters\nvar builder = new QueryStringBuilder(\"/?p1=o1\");\n// Add second parameter\nbuilder.Add(\"p2\", \"o2\");\n// Should return /?p1=o1\u0026p2=o2\nvar url = builder.ToString();\n```\n\n### Extensions\n\n- `DateTimeExtensions`:\n    - `ToEpochTime` - Returns a Unix Epoch time;\n    - `EndOfDay` - Returns end of the day datetime `dd.mm.yyyy 23:59:59`;\n    - `BeginningOfDay` - Returns beginning of the day datetime `dd.mm.yyyy 00:00:00`;\n    - `IsToday` - Checks if date is today (Should be in UTC);\n    - `IsTomorrow` - Checks if date is tomorrow (Should be in UTC);\n    - `IsYesterday` - Checks if date is yesterday (Should be in UTC);\n    - `ToTimestamp` - Converts datetime to timestamp.\n- `EnumerableExtensions`:\n    - `ForEach` - Applies an action on each item of the sequence;\n    - `SafeOfType` - Filters the elements of an IEnumerable based on a specified type;\n    - `OrEmptyIfNull` - Returns empty sequence if source sequence is null otherwise returns source sequence;\n    - `IsNullOrEmpty` - Checks whether given sequence is null or empty;\n    - `FilterPaging` - Filters by page and page size;\n    - `Singleton` - Transforms item into IEnumerable with one item;\n    - `Partition` - Splits IEnumerable into multiple partitions;\n    - `DistinctBy` - Selects distinct values from list;\n    - `Concat` - Can concatenate 2 or more sequences into signle.\n- `StringExtensions`:\n    - `JoinStrings` - Transforms list into a separated string;\n    - `GenerateSlug`, `GenerateSlugWithoutHyphens` - Creates URL / Html friendly slug;\n    - `TryParseInt32` - Parses string to nullable int (Int32);\n    - `TryParseInt64` - Parses string to nullable long (Int64);\n    - `TryParseBool` - Parses string to nullable boolean;\n    - `TryParseTimeSpan` - Parses string to nullable TimeSpan;\n    - `TryParseDecimal` - Parses string to nullable decimal;\n    - `IsNullOrEmpty` - Answers true if this String is either null or empty;\n    - `HasValue` - Answers true if this String is neither null or empty;\n    - `HtmlEncode` - Encodes the string as HTML;\n    - `HtmlDencode` - Decodes an HTML string;\n    - `UrlEncode` - Encodes the string for URLs;\n    - `UrlDecode` - Decodes a URL-encoded string;\n    - `IsAbsoluteUrl` - Checks if a string is absolute URL;\n    - `IsRelativeUrl` - Checks if a string is relative URL;\n    - `GetHead` - Returns beginning of the string and adds ellipse `...` if string is longer that specified by length;\n    - `GetTail` - Returns ending of the string and adds ellipse `...` if string is longer that specified by length;\n    - `Capitalize` - Capitalizes every word (title case).\n- `FluentExtensions` - Provides fluent way of chaining methods\n    - `T If\u003cT\u003e(this T source, bool condition, Func\u003cT, T\u003e func)`\n    - `T If\u003cT\u003e(this T source, Func\u003cbool\u003e condition, Func\u003cT, T\u003e func)`\n    - `T If\u003cT\u003e(this T source, Func\u003cT, bool\u003e condition, Func\u003cT, T\u003e func)`\n    - `T Fluent\u003cT\u003e(this T source, Action\u003cT\u003e action)`\n\nSome `FluentExtension` examples:\n\n```csharp  \nvar list = new List\u003cstring\u003e()\n                .Fluent(l =\u003e l.Add(\"Hello\"))\n                .Fluent(l =\u003e l.Add(\", \"))\n                .Fluent(l =\u003e l.Add(\"World!\")); \n```\n\n```csharp  \nstring value1 = null;\nvar value2 = string.Empty;\nvar value3 = \"Hello\";\n\nvar list = new List\u003cstring\u003e()\n    .If(!string.IsNullOrEmpty(value1), l =\u003e l.FluentAdd(value1))\n    .If(!string.IsNullOrEmpty(value2), l =\u003e l.FluentAdd(value2))\n    .If(!string.IsNullOrEmpty(value3), l =\u003e l.FluentAdd(value3));\n```\n\n```csharp\nvar value = \"Hello\";\n\nvar list = new List\u003cstring\u003e()\n    .If(true, l =\u003e\n        l.If(() =\u003e !string.IsNullOrEmpty(value),\n            l1 =\u003e l1.FluentAdd(value)));\n```\n\n- `AsyncExtensions` - provides various extension methods to help working with async code\n    - `GetAwaiter(this CancellationToken ct)` - allows to `await` on `CancellationToken`\n\nExample (subscribing to GraphQL subscription and handling the message):\n\n```csharp\npublic async Task SubscribeAndHandleMessagesAsync(CancellationToken cancellationToken)\n{\n    var query = \"subscription { ... }\";\n    var graphQlClient = new GraphQLHttpClient(url);\n    var observable = graphQlClient.CreateSubscriptionStream\u003cResultDto\u003e(query);\n\n    observable\n        .SelectMany(r =\u003e Observable.FromAsync(() =\u003e HandleAsync(r)))\n        .Subscribe();\n\n    // as `Subscribe()` method exits immediately after invoke\n    // we have to sit here and wait until cancellation token is cancelled (from outer scope)\n    // having extension method `GetAwaiter` on `CancellationToken` allows us to do so\n    await cancellationToken;\n}\n\nprivate async Task\u003cUnit\u003e HandleAsync(GraphQLResponse\u003cResultDto\u003e result)\n{\n    // handle the message\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeta%2Fgeta-dotnet-extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeta%2Fgeta-dotnet-extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeta%2Fgeta-dotnet-extensions/lists"}