{"id":21864779,"url":"https://github.com/fluxera/fluxera.utilities","last_synced_at":"2025-04-14T21:02:03.842Z","repository":{"id":38302186,"uuid":"435611342","full_name":"fluxera/Fluxera.Utilities","owner":"fluxera","description":"A collection of common utilities and extension methods.","archived":false,"fork":false,"pushed_at":"2025-02-05T11:29:41.000Z","size":276,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-11T08:43:20.426Z","etag":null,"topics":["conversion","convert","csharp","dotnet","dotnet7","extension-methods","extensions","util","utilities","utility","utils"],"latest_commit_sha":null,"homepage":"","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/fluxera.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":"2021-12-06T18:51:50.000Z","updated_at":"2025-02-05T11:29:24.000Z","dependencies_parsed_at":"2024-02-22T16:30:41.777Z","dependency_job_id":"9c334677-8a78-433e-9bde-c376ea59fa94","html_url":"https://github.com/fluxera/Fluxera.Utilities","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluxera%2FFluxera.Utilities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluxera%2FFluxera.Utilities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluxera%2FFluxera.Utilities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluxera%2FFluxera.Utilities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fluxera","download_url":"https://codeload.github.com/fluxera/Fluxera.Utilities/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961201,"owners_count":21189991,"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":["conversion","convert","csharp","dotnet","dotnet7","extension-methods","extensions","util","utilities","utility","utils"],"created_at":"2024-11-28T04:12:23.579Z","updated_at":"2025-04-14T21:02:03.792Z","avatar_url":"https://github.com/fluxera.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://dev.azure.com/fluxera/Foundation/_apis/build/status/GitHub/fluxera.Fluxera.Utilities?branchName=main\u0026stageName=BuildAndTest)](https://dev.azure.com/fluxera/Foundation/_build/latest?definitionId=76\u0026branchName=main)\n\n# Fluxera.Utilities\n\nA collection of common utilities and extension methods.\n\nThis is the place for all \"common\" helpers, extension methods and utilities. There is only one condition: The helpers may not require any third party packages.\n\n## Available Helpers\n\n- **```AsyncHelper```** Run async method in a synchonous context.\n- **```RandomHelper```** Useful randomizing methods.\n- **```TempPathHelper```** Create temp files or folders safely.\n- **```Disposable```** Base class that implements ```IDisposable``` correctly.\n\n## Available Collections\n\n- **```SortedList```**  ```IList\u003cT\u003e``` implementation that inserts the items sorted using binary search.\n\n## Available Extensions Methods\n\nThere are a lot of extensions methods available. here we sort them by the type they are implemented on.\n\n### Array\n\n- **```IsIndexWithin```** Checks if the given index is within the array.\n- **```ToMemoryStream```** Creates a ```MemoryStream``` from a byte array.\n\n### Assembly\n\n- **```GetResourceAsStringAsync```** Gets the content of the given embedded resource location as string.\n\n### Character\n\n- **```Repeat```** Repeats the given ```char``` the specified number of times.\n\n### Collection\n\n- **```AddIfNotContains```** Adds item(s) to collection if they are not already in the collection.\n- **```IsNullOrEmpty```** Checks if the collection is null or empty.\n- **```RemoveMatching```** Removes all items from the collection that match a given predicate.\n\n### String Conversions\n\nThe custom interfaces ```IConverter``` and ```ITryConverter``` provide a fluent interface for\nconverting strings to numeric, boolean and Guid values.\n\n```c#\nstring value = \"5\";\nint result = value.Convert().ToInt();\n\nstring value = \"5\";\nbool success = value.TryConvert().ToInt(out int result);\n```\n\n```c#\nchar value = '5';\nint result = value.Convert().ToInt();\n\nchar value = '5';\nbool success = value.TryConvert().ToInt(out int result);\n```\n\nThe ```Convert()``` extension methods also provide overloads to provide a custom ```IFormatProvider```. The default format provider is ```CultureInfo.CurrentCulture```.\n\n### DateTime\n\n- **```AddMonthsToEndOfMonth```** Adds the months to end of month.\n- **```AddWeeks```** Adds an amount of weeks to a date value.\n- **```CalculateAge```** Calculates the age based on a passed reference date.\n- **```GetDayCountOfYear```** Get the number of days within that date year.\n- **```GetDays```** Get the number of days between two dates.\n- **```GetDaysOfMonthCount```** Returns the number of days in the month of a provided date.\n- **```GetFirstDayOfMonth```** Returns the first day of the month of a provided date.\n- **```GetFirstDayOfWeek```** Gets the first day of the week using a specific culture.\n- **```GetLastDayOfMonth```** Returns the last day of the month of a provided date.\n- **```GetLastDayOfWeek```** Gets the last day of the week using a specific culture.\n- **```GetNextWeekday```** Gets the next occurrence of the specified weekday.\n- **```GetPeriodOfDay```** Returns the period of the day ```PeriodOfDay.Morning```, ```PeriodOfDay.Afternoon```, ```PeriodOfDay.Evening```.\n- **```GetPreviousWeekday```** Gets the previous occurrence of the specified weekday.\n- **```GetWeekOfYear```** Gets the week number for a date time value based on the current culture settings.\n- **```GetWeeksWeekday```** Gets the next occurrence of a specified weekday within the current week using a specific culture.\n- **```IsDateEqual```** Determines if the date part of two ```DateTime``` values are equal.\n- **```IsLeapYear```** Returns if or not a ```DateTime``` is during a leap year.\n- **```IsTimeEqual```** Determines if the time part of two ```DateTime``` values are equal.\n- **```IsToday```** Determines if a date is ```DateTime.Today```.\n- **```IsWeekday```** Determines if a ```DateTime``` or ```DayOfWeek``` is a weekday.\n- **```IsWeekend```** Determines if a ```DateTime``` or ```DayOfWeek``` is a weekend.\n- **```Midnight```** Gets a ```DateTime```representing midnight on a specified date.\n- **```NextMonth```** Gets the next month.\n- **```Noon```** Gets a ```DateTime``` representing noon on a specified date.\n- **```OrdinalSuffix```** Converts the day of a date to an ordinal string, f.e. 3 to '3rd'.\n- **```SetTime```** Sets the time of the a ```DateTime``` with a specified precicion. All other parts are set to zero.\n- **```ToUnixTimestamp```** Converts a ```DateTime``` to a UNIX timestamp (seconds since 01.01.1970).\n\n### Dictionary\n\n- **```ContainsValue```** Returns ```true``` if the value is contained in a dictionary.\n- **```GetOrAdd```** Gets a value from a dictionary with given key. Returns a default value if the value cannot be found.\n- **```GetOrDefault```** Gets a value from a dictionary. Returns ```default``` if the value cannot be found.\n- **```TryGetValue```**  Tries to get a value from a dictionary.\n\n### Enum\n\nAll operations utilize a cache of the enums metadata that is built lazily when using the extensions methods.\n\n- **```EnumOptions```** Gets all options of an enum type.\n- **```EnumValues```** Gets all values of an enum type.\n- **```HasFlag```**  A generic version of ```Enum.HasFlag(enum)\"```\n- **```IsEmpty```** Gets a flag, indicating if the enum has no values.\n- **```MaxValue```** Gets the maximum value of the enum.\n- **```MinValue```** Gets the minimum value of the enum.\n\n### Enumerable\n\n- **```AsReadOnly```** Converts an enumerable to a read-only collection.\n- **```ForEach```** Executes an ```Action``` for every item in the enumerable.\n- **```IsAny```** Checks if a enumerable is not null or empty.\n- **```IsNullOrEmpty```** Checks if the enumerable is null or empty.\n\n### Guid\n\n- **```IsEmpty```** Checks a ```Guid``` is ```Guid.Empty```.\n\n### List\n\n- **```AddFor```** Adds a value to a list if the value matches a predicate.\n- **```AddRange```** Adds values to a list (```IList\u003cT\u003e```).\n- **```AddRangeFor```** Adds values to a list if the value to add matches a predicate.\n- **```AddRangeSorted```**  Adds values into a list sorted.\n- **```AddSorted```** Adds a value into a list sorted.\n\n### MemoryStream\n\n- **```ToContentString```** Converts the content of the memory stream to a string.\n\n### Nullable\n\n- **```IsNull```** Checks if a nullable has no value.\n\n### Numeric\n\nThe numeric extensions methods are available for the following primitives: ```byte```, ```short```, ```int```, ```long```\n\n- **```IsBetween```** Determines if a value is between the specified values a and b (inclusive).\n- **```IsEven```** Determines whether a value is even.\n- **```IsOdd```** Determines whether a value is odd.\n- **```Ordinalize```** Ordinalize a number, f.e. 6 to '6th'.\n- **```Times```** Performs a specified action n times based on the value.\n\n### Object\n\n- **```GetDefaultValue```** Gets the type default value for a type. In case of reference types: ```null``` and for values types ```default(T)```.\n- **```IsNull```** Returns ```true```, if the specified target reference is equal to the null reference.\n- **```Locking```** Executes an ```Action``` by locking on a given object.\n\n### Principal\n\n- **```GetClaimValue```** Gets the first value of the given claim type and returns its value.\n- **```GetClaimValues```** Gets all values of the given claim type and returns their values.\n- **```GetDisplayName```** Gets the display name from the ```ClaimsIdentity``` or uses the subject.\n- **```GetSubjectId```** Gets the subject identifier.\n- **```IsAuthenticated```** Determines whether a principal is authenticated.\n\n### Reflection\n\n- **```DefinesAttribute```** Returns ```true``` if a ```MemberInfo``` instance is marked with the specified attribute.\n- **```GetMemberType```**  Gets the underlying type of a ```MemberInfo``` instance.\n- **```IsIndexer```** Determines if a ```PropertyInfo``` is an indexer.\n- **```IsProperty```** Determines if a ```MethodInfo``` is a property.\n- **```IsPropertyGetter```** Determines if a ```MethodInfo``` is a property getter.\n- **```IsPropertySetter```** Determines if a ```MethodInfo``` is a property setter.\n\n### Stream\n\n- **```CopyTo```** Copies a ```Stream``` into a another one.\n- **```CopyToMemory```** Copies a ```Stream``` into a local ```MemoryStream```.\n- **```GetBytes```** Gets all bytes of a ```Stream```.\n- **```GetReader```** Opens a ```StreamReader``` for a ```Stream```.\n- **```GetWriter```** Opens a ```StreamWriter``` for a ```Stream```.\n- **```Rewind```** Rewinds (set the current position to 0) a ```Stream```.\n- **```Write```** Writes all bytes to the a ```Stream```.\n\n### String\n\n- **```ConcatWith```**  Concatenates a string with additional strings and an optional delimiter character.\n- **```EnsureEndsWith```** Ensures that a string ends with a given suffix.\n- **```EnsureStartsWith```** Ensures that a string starts with a given prefix.\n- **```FormatInvariantWith```** Applies formatting to a string using the invariant culture.\n- **```FormatWith```** Applies formatting to a string using the current culture.\n- **```FromBase64```** Decodes a string from base64 to its normal representation.\n- **```GetBytes```** Converts a string to a ```byte[]``` using a specific encoding.\n- **```IsNullOrEmpty```** Determines if a string is ```null``` or ```string.Empty```.\n- **```IsNullOrWhiteSpace```**Determines if a string is ```null``` or ```string.Empty``` or consists of whitespace-only characters.\n- **```IsNumeric```** Checks if the contents of a string is a numeric value.\n- **```Left```** Gets a substring of a string from beginning of the string.\n- **```RemovePostFix```** Removes the first occurrence of postfixes from the end of a string.\n- **```RemovePrefix```** Removes the first occurrence of prefixes from the beginning of a string.\n- **```RemoveSpaces```** Removes all whitespace (not line endings, etc.) from a string.\n- **```RemoveSpecialCharacters```** Removes all special characters from a string.\n- **```Repeat```** Repeats a string value as provided by the repeat count.\n- **```ReplaceDiacritics```** Replaces all diacritical marks with an ascii representation, fe. 'ü' to 'u'.\n- **```ReplaceWithEmpty```** Replaces all occurrences of a string in an input string with ```string.Empty```.\n- **```Reverse```**Reverses the a string.\n- **```Right```** Gets a substring of a string from end of the string.\n- **```Split```** Uses ```string.Split(string[], StringSplitOptions)``` method to split a string by a separator.\n- **```ToBase64```** Encodes string to base64.\n- **```ToEnum```** Converts a string to a matching enum value of a given enum type.\n- **```ToMemoryStream```** Converts a string to a ```MemoryStream```.\n- **```Truncate```**  Truncates a string to a specified length and optionally replaces the truncated part with '...' suffix.\n- **```UrlSafeDecode```** Encodes a string for safe usage in URLs, f.e. for password reset or email confirmation tokens.\n- **```UrlSafeEncode```** Decodes a given URL-safe string.\n\n#### Inflection\n\n- **```Pluralize```**  Returns the plural form of a word.\n- **```Singularize```** Returns the singular form of a word.\n- **```Titleize```** Return a string in a form that can be used as title.\n- **```Humanize```** Humanizes a string.\n- **```Pascalize```** Pascalizes a string.\n- **```Camelize```** Camelizes a string.\n- **```Underscore```** Replaces all dashes with underscores.\n- **```Capitalize```** Capitalizes a string.\n- **```Uncapitalize```** Uncapitalizes a string.\n- **```Ordinalize```** Ordinalizes the given number that is given as string, f.e. '6' to '6th'.\n- **```Dasherize```** Converts all underscores to dashes.\n\n### Type\n\n- **```CreateInstance```** Creates an instance of a type.\n- **```DefinesAttribute```** Returns ```true```if the type is marked with a specified attribute.\n- **```GetBaseClasses```** Gets all base classes recursively for a type.\n- **```Implements```** Returns ```true``` if type implements a specified interface.\n- **```IsAssignableTo```** Checks if a type is assignable to another type.\n- **```IsCollection```** Determines if the a type is a collection.\n- **```IsEnumerable```** Determines if the a type is an enumerable.\n- **```IsNullable```** Determines if the a type is a nullable.\n- **```IsNumeric```** Determines if the a type is numeric.\n- **```IsPrimitive```** Determines whether a type is a primitive.\n- **```UnwrapNullableType```** Gets the type without nullable if the type is a ```Nullable\u003cT\u003e```.\n\n### Uri\n\n- **```GetSubDomain```** Gets the sub-domain part from a ```Uri```.\n\n### ValueType\n\n- **```IsDefault```** Determines if a value is empty (```default(T)```).\n- **```IsNullable```** Determines if a type is a nullable.\n- **```ToNullable```** onverts a value to a corresponding nullable type.\n\n\n# Fluxera.ComponentModel.Annotations\nA collection of custom data annotations.\n\n## Available Attributes\n\n### Datastore related attributes\n\n- **```[CompositeIndex]```** \n  - An attribute to provide the composite indices of an entity.\n  - Targets classes.\n  - Allows multiple.\n- **```[DateOnly]```**\n  - A marker attribute to signal potential data stores to only store the date.\n  - Targets properties and fields.\n  - Denys multiple.\n- **```[DatePrecision]```**\n  - An attribute to provide the date precision to potential data stores.\n  - Targets properties and fields.\n  - Denys multiple.\n- **```[Ignore]```**\n  - A marker attribute to signal potential data stores to ignore this value.\n  - Targets properties and fields.\n  - Denys multiple.\n- **```[Index]```**\n  - An attribute to provide an index of the entity.\n  - Targets properties and fields.\n  - Denys multiple.\n- **```[Reference]```**\n  - An attribute to signal potential data stores that this property should be stored as database reference.\n  - Targets properties and fields.\n  - Denys multiple.\n\n## Validation attributes\n\n- **```[Contains]```**\n  - A validation that checks if the annotated property contains the given check value.\n  - Targets properties and fields.\n  - Denys multiple.\n- **```[EndsWith]```**\n  - A validation attribute that checks if the value end with the given value.\n  - Targets properties and fields.\n  - Denys multiple.\n- **```[EnforceTrue]```**\n  - A validation attribute that checks if the value is ```true```.\n  - Targets properties and fields.\n  - Denys multiple.\n- **```[ListLength]```**\n  - A validation attribute to check the length of a list.\n  - Targets properties and fields.\n  - Denys multiple.\n- **```[ListMaxLength]```**\n  - A validation attribute to check the maximum length of a list.\n  - Targets properties and fields.\n  - Denys multiple.\n- **```[ListMinLength]```**\n  - A validation attribute to check the minimum length of a list.\n  - Targets properties and fields.\n  - Denys multiple.\n- **```[NotEmpty]```**\n  - A validation attribute to check if an enumerable contains at least one element.\n  - Targets properties and fields.\n  - Denys multiple.\n- **```[RequiredIf]```**\n  - A validation attribute that checks if the value is required when a condition is met.\n  - Targets properties and fields.\n  - Denys multiple.\n- **```[StartsWith]```**\n  - A validation attribute that checks if the value starts with the given value.\n  - Targets properties and fields.\n  - Denys multiple.\n\n## Datatype attributes\n\n- **```[Currency]```**\n  - A data-type attribute for currency values.\n  - Targets properties, fields and parameters.\n  - Denys multiple.\n- **```[Date]```**\n  - A data-type attribute for date values.\n  - Targets properties, fields and parameters.\n  - Denys multiple.\n- **```[DateTime]```**\n  - A data-type attribute for date-time values.\n  - Targets properties, fields and parameters.\n  - Denys multiple.\n- **```[Duration]```**\n  - A data-type attribute for duration (timespan) values.\n  - Targets properties, fields and parameters.\n  - Denys multiple.\n- **```[ImageUrl]```**\n  - A data-type attribute for image-url values.\n  - Targets properties, fields and parameters.\n  - Denys multiple.\n- **```[MultilineText]```**\n  - A data-type attribute for multiline text values.\n  - Targets properties, fields and parameters.\n  - Denys multiple.\n- **```[Password]```**\n  - A data-type attribute for password values.\n  - Targets properties, fields and parameters.\n  - Denys multiple.\n- **```[PostalCode]```**\n  - A data-type attribute for postal code values.\n  - Targets properties, fields and parameters.\n  - Denys multiple.\n- **```[Select]```**\n  - A data-type attribute to signal that the values comes from a selection of values.\n  - Targets properties, fields and parameters.\n  - Denys multiple.\n- **```[Text]```**\n  - A data-type attribute for text values.\n  - Targets properties, fields and parameters.\n  - Denys multiple.\n- **```[Time]```**\n  - A data-type attribute for time values.\n  - Targets properties, fields and parameters.\n  - Denys multiple.\n- **```[Upload]```**\n  - A data-type attribute for upload values.\n  - Targets properties, fields and parameters.\n  - Denys multiple.\n\n\n# Fluxera.Linq.Expressions\n\nA collection of LINQ expression utilities and extension methods.\n\n## Usage\n\nThe extenions methods use several utility classes that are publicly available through\nthis library to be used forother use-cases:\n\n- **```Evaluator```** Enables the partial evaluation of queries.\n- **```LocalCollectionExpander```** Expands local collection values.\n- **```ParameterRebinder```**  Used for rebinding of parameters.\n\nThe utility classes are used to evaludate as much as possible to create a string representation of an ```Expression```.\nThe result of the extension can f.e. be used to create cache keys for expression-based data queries.\n\n```c#\nExpression\u003cFunc\u003cPerson, string\u003e\u003e expression = x =\u003e x.Name;\nstring? str = expression.ToExpressionString();\n```\n\nThe other extension methods can be used to compose given expressions.\n\n- **```And```** Creates an ```Expression``` that represents an bitwise AND operation.\n- **```AndAlso```** Creates an ```Expression``` that represents a conditional AND operation that evaluates the second operand only if it has to.\n- **```Or```** Creates an ```Expression``` that represents an bitwise OR operation.\n- **```OrElse```** Creates an ```Expression``` that represents a conditional OR operation that evaluates the second operand only if it has to.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluxera%2Ffluxera.utilities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluxera%2Ffluxera.utilities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluxera%2Ffluxera.utilities/lists"}