# Abstractions

**Structr.Abstractions** package contains number of classes and extension methods to supply wide range of developer basic needs in different situations.

Big part of package consists of extensions for most popular types allowing to avoid redundant code in widespread cases.

For example You need to add elements to dictionary while overriding values for already existing keys, then you choice is [AddRangeOverride](/utilities/abstractions/extensions/dictionary.md) dictionary extension. Or some text should be formatted to hyphen-case style. Then [ToHyphenCase](/utilities/abstractions/extensions/string.md) string extension supplies your needs. Maybe your collection needs some tricky ordering by several fields and directions - advanced [OrderBy](/utilities/abstractions/extensions/enumerable.md) supplies everything needed. Checking input variables is most common case and many of us are bored by typing another if-null-then-throw statements. [Ensure.NotNull](/utilities/abstractions/ensure.md) (InRange, GreaterThan, etc.) does all this job in one line.

This isn't all. There are extensions for more than ten types, tools for working with async methods, enums, sequential guids, tree-like structures, money types and more. List of all possibilities located below as do some samples.

## Installation

Abstractions package is available on [NuGet](https://www.nuget.org/packages/Structr.Abstractions/).

```
dotnet add package Structr.Abstractions
```

## Contents

* [Check](/utilities/abstractions/check.md)
* [Ensure](/utilities/abstractions/ensure.md)
* [Money](/utilities/abstractions/money.md)
* [HierarchyId](/utilities/abstractions/hierarchyid.md)
* [Providers](/utilities/abstractions/providers.md)
  * [SequentialGuidProvider](/utilities/abstractions/providers/sequentialguidprovider.md)
* [Extensions](/utilities/abstractions/extensions.md)
  * [DateTime](/utilities/abstractions/extensions/datetime.md)
  * [Dictionary](/utilities/abstractions/extensions/dictionary.md)
  * [DirectoryInfo](/utilities/abstractions/extensions/directoryinfo.md)
  * [Enumerable](/utilities/abstractions/extensions/enumerable.md)
  * [Enum](/utilities/abstractions/extensions/enum.md)
  * [Expression](/utilities/abstractions/extensions/expression.md)
  * [Long](/utilities/abstractions/extensions/long.md)
  * [MemberInfo](/utilities/abstractions/extensions/memberinfo.md)
  * [Object](/utilities/abstractions/extensions/object.md)
  * [Queryable](/utilities/abstractions/extensions/queryable.md)
  * [ServiceCollection](/utilities/abstractions/extensions/servicecollection.md)
  * [String](/utilities/abstractions/extensions/string.md)
  * [Type](/utilities/abstractions/extensions/type.md)
* [Helpers](/utilities/abstractions/helpers.md)
  * [AsyncHelper](/utilities/abstractions/helpers/asynchelper.md)
  * [BindHelper](/utilities/abstractions/helpers/bindhelper.md)
* [JsonConverters](/utilities/abstractions/jsonconverters.md)
  * [DateOnly](/utilities/abstractions/jsonconverters/dateonly.md)
  * [TimeOnly](/utilities/abstractions/jsonconverters/timeonly.md)
  * [StringNumber](/utilities/abstractions/jsonconverters/stringnumber.md)

## Samples for some of methods

### AddRangeOverride

Example of mentioned above `AddRangeOverride` dictionary extension:

```csharp
var dictionary = new Dictionary<int, string>
{
    { 1, "One" },
    { 2, "Two" },
    { 3, "Three" },
    { 4, "Four" }
};
var newDictionary = new Dictionary<int, string>
{
    { 1, "One_overridden" },
    { 3, "Three_overridden" },
    { 5, "Five_new" }
};
dictionary.AddRangeOverride(newDictionary);
```

So after applying extension method will look like:

```csharp
{ 1, "One_overridden" },
{ 2, "Two" },
{ 3, "Three_overridden" },
{ 4, "Four" },
{ 5, "Five_new" }
```

### GetDisplayName

Allows to get Display attribute value for enums:

```csharp
private enum FooBarBaz
{
    Foo,
    [Display(Name = "BarBarBar")]
    Bar,    
    [Display(Name = "displayNameForEnumBaz", ResourceType = typeof(SomeResources))]
    Baz
}

string d1 = FooBarBaz.Foo.GetDisplayName(); // Foo, because no display name was provided
string d2 = FooBarBaz.Bar.GetDisplayName(); // BarBarBar
string d3 = FooBarBaz.Baz.GetDisplayName(); // Value will be taken from SomeResources file
```

### ToFileSizeString

Converts `long` variable to human readable file size in kilobytes, megabytes etc.

```csharp
12L.ToFileSizeString(); // ---> 12.0 bytes
2200L.ToFileSizeString(); // ---> 2.1 KB
3330000L.ToFileSizeString(); // ---> 3.2 MB
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.structr.dev/utilities/abstractions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
